Search This Blog

Tuesday, June 14, 2011

Git in a few words

I finally started to use Git after years of SVN. I've heard so many times that Git is awesome, but so far I've forced to use SVN, so I've never even tried Git. Enough of me. The purpose of this post is to point you to a very simple, yet comprehensive Git tutorial: http://gitimmersion.com/. Enjoy!


If you are inpatient and don't want to read the tutorial (I highly recommend reading it), here are some typical git workflows I have encountered so far:

Create a branch and the marge it to master:

git checkout -b newBranchName

This command will create a new branch and will "move" all your uncommitted changes to this new branch. The you can keep adding and committing changes to this branch. When you are ready to merge into master type:

git checkout master

This command will switch back to master. Here you should pull to get any possible changes you or someone else have pushed into master):

git pull origin master

Now you are ready to merge:

git merge newBranchName

If you are lucky, there won't be any conflicts and you can skip the next command. If there conflicts, type:

git mergetool

This tool will open a graphical interface to solve conflicts. IMPORTANT: if there are more than one files with conflicts, quit the graphical interface after solving the conflicts for each file (note that I wrote quit, not just close). Fortunately, the mergetool will reopen the interface for all subsequent files in conflict.

After all conflicts have been solved, you can commit:

git commit


(I recommend not entering comments for this particular commit, so the default merge comment is used). Finally, you can push your changes:

git push origin master

Optionally, you can delete the branch you created originally:

git branch -d newBranchName

Or if you want to switch back and keep working on the branch:

git checkout newBranchName


Hope that helps someone out there!


(12/08/2011 update): This link presents a comprehensive overview of branches in GIT and how to master them. Definitively a must read.

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete

  2. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru Dot Net Training in Chennai. Nowadays Dot Net has tons of job opportunities on various vertical industry.
    or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

    ReplyDelete