Friday, May 20, 2011

Branching and Merging in Git/GitHub

I little bit of introduction, I have been using Git for my personal projects for quite a bit now and I love it! I used CVS and Subversion and to be honest Git is the best for the job. I tried to implement it in my work but I guess they did not like it anyways that is another history. I also use GitHub as a repository which is really good you can set up an account and repository really fast and as long as your project is open source the storage is free, you a limit though, it is more than enough for a project that is for sure. I also used Google Code and to be honest I prefer GitHub just because Google Code uses Subversion.

You can't explain Git in one post because it is so big and there are tons of ways to do the same thing, that is why I like it so much, among others though. If you want a complete guide to learn Git, I would suggest Pro Git which is free and really really complete.

Now, to the point. I just published my first Android Application to the Android Market (more on this later) :) it is not really that big. It is something I built in my free time and to learn Android. It is nice I like it a lot and I am planning more things. Anyways, I had to create a branch to separate the stable version which is published right now, from the dev version since I am still adding more things. Branching in Git is so easy! really I wish Subversion was that easy. Although, I had to create a remote branch since I am using GitHub either way was easier than anything else so these are the steps to accomplish this:

git pull origin master                 -- to get everything from your repository
git branch <name of your branch>       -- creating the branch
git checkout <name of your branch>     -- changing to the new branch
-- make all the changes you need
git push origin <name of your branch>  -- pushing the new branch to your github repository

If you are done with your branch and all your tests have been completed it is time to merge. Merging is also really easy just one command and that is all:

git merge <name of your branch>  -- will merge <name of your branch> on top of the current branch you are working on

More useful commands are:
git status         -- to check the status and what has changed
git branch         -- will list all your branches
git add .          -- will add all the files modified to a commit ready state

There are a lot of commands and a lot of ways to accomplish the same thing so I strongly recommend to read the documentation to get familiar with all the possibilities.

Happy coding :)

No comments:

Post a Comment