Git cheet sheet

Git took the world of version control systems by storm. Every serious development team has switched to a distributed version control system. This doesn’t need to be Git, there are others like Mercurial, Monotone, Fossil, BitKeeper etc. At the moment Git seems to be the most popular. This may change in the future.
Git’s functionality is overwhelming. Especially for newbies or developers that are used to a client-server based version control system. In this article I want to document the most common scenarios, that I face on a daily to weekly basis.

Case: You start working on a new feature and need to create a feature branch for that.

Solution: Create a new feature branch from master.

git checkout -b [feature-branch]

After implementing the desired feature we want to push the branch to the remote repository.

git push -u origin [feature-branch]

With -u git sets the tracking information during push.

Case: You’ve done some changes locally on the master branch but now you want to override them with the current state of the master branch. These changes are already committed but only locally.
Solution: Fetch the commits from the remote repository, set the working copy to the tip of the master branch

git fetch origin
git reset –hard origin/master

Case: You’re working on a feature branch and want to update daily your changes from master, so you don’t have a huge merge operation when your feature in implemented.

Solution: Pull the current changes from master and rebase them into your feature branch so you keep time line in tact.

git pull origin master –rebase