Debdeep Bhattacharya

View My GitHub Profile

Creating git repositories

1 Oct 2021

Let’s assume that we created an account on GitHub with user <username> and created a repository called testconfigs.

SSH access to GitHub

eval `ssh-agent -s`

(Here, these are two backticks, not apostrophes). Then run:

ssh-add
cat ~/.ssh/id_rsa.pub
ssh -T git@github.com

(Caution: not your username or id, but the username git)

This is most probably a routine check that you have the access. This does not give you a remote tty or you do not need to stay logged in to perform git tasks. You can probably skip this step.

git config --global user.email "email@domain.com"
git config --global user.name "Name"
.ssh/id_rsa.pub | ssh user@server 'cat >> .ssh/authorized_keys'
Host nickname
   User <username>
   HostName serve.server.address

To push/pull git repository without password

Change the URL origin type of your repository to an ssh-based one using:

git remote set-url origin git@github.com:<username>/<repository_name>.git

After that, any git pull/push will go through without having to enter the password.

Creating an empty local repository

Create some empty directories in your repository, which will be your working directory. Then run:

git init

This will create a .git directory inside the local repository. Now add the address of the remote host, which we are naming gitty, using

git remote add gitty git@github.com:<username>/testconfigs

The repository testconfigs will be referred to as gitty.

You can see all the remote hosts by: git remote -v If needed, you can delete a remote host by : git remote rm nickname_of_host

Now download all the files from the master branch of gitty by: git pull gitty master Now your working directory will have all the files stored in gitty. You can modify them, add more files etc. After modification, add the files to the modification list using:

git add file1
git add file2
git add file3

etc.

After they are added to the changelist, it is the time to commit to the change and add a comment about the changes:

git commit -m "Added file1, file2, changed file3"

After committing, it is time to upload the change back to the place by:

git push gitty master

(Obviously we are uploading to the master branch here) (Here, for the first time you may be asked to enter your email id and username. Follow the instruction to add these info to the file ~/.gitconfig)

And we are done.

Maintaining the local repository:

Create a new repository in the website. Copy the clone address. Locally do

	 git clone https://github.com/username/reponame

Now you have a local repo.

        cd reponame

Add files/make changes e.g. cp path/file . Add to the git list :

git add file
git commit -m 'message'
git push

Provide username and password for your git repo. If you don’t want to enter username/password repeatedly, add a remote repo:

git remote add petname git@github.com:username/reponame

Next, push to the repo called petname like this

git push petname

Then you won’t be asked for credentials anymore. And by default it will get pushed to the master branch .

Adding and committing only the files that are in the git ls-files list:

git commit -am "Staging and committing all the modifications done to files in git ls-files"

Alternatively, get commit -a -m text" works.