Git is a distributed source code management system. A very powerful, fast and reliable way of managing source code. I started working with Git in 2010 and I found it better than any other non distributed SCM. I thought of sharing all basic Git operation which one can use and become productive very fast.
Please note : This article does not focus on Git vs SVN or CVS. This gives information on most useful commands with Git which can help a person to quick start with it.
Most useful commands with Git:
$ ssh-keygen -C "email-id" -t rsa
git config --global user.email email-id
git config --global user.name "Dharmesh Borad"
1> How to create Git repository :
$ git init
2> Add remote repository :
$ git remote add github firstname.lastname@example.org:/platform.git
Branching and Merging operation with Git
1> Creating branch under this repository
$ git branch branchname
2> Listing all branch under this repository
$ git branch
3> To switch between branches. Below command will switch to newly created branch i.e. “branchname”.
$ git checkout branchname
4> To merge with master branch (branchname -> master)
$ git checkout master
$ git merge branchname
5> To delete/remove branch
$ git branch -d branchname
6> To delete branch on remote machine(origin alias of remote machine/repository)
$ git push origin :branchname
1> Adding files to repository index for further commit
$ git add filename
2> Adding folder to repository index for further commit. This will add files from that folder also.
$ git add foldername/
1> To remove file/folder form .git index but to not remove physically
$ git rm –cached filename
2> To remove files from index as well as from physical storage. Use –r for recursive remove.
$ git rm -r myfolder/
$ git rm myfile
1> Committing to local repository. –a is for all and to skip staging area. –m is for message.
$ git commit -a -m "commit message"
1> Pulling from repository
$ git pull remotename branchname
2> Pushing to repository
$ git push remotename branchname
1> To get help on any command
$ git help commandname
To fetch branch from remote repository
git remote show origin
1> If the remote branch which you want to checkout is under “New remote branches” and not under “Tracked remote branches” then you need to fetch them first from remote
git fetch branchane
2> Now it will allow to create branch out of fetched one
git checkout -b local-name origin/remote-name
In case if you are looking for some very specific operation please write me back. I will try to give details in my free time.