Hell Oh Entropy!

Life, Code and everything in between

git branching awesomeness

Posted: Nov 14, 2009, 20:03

Branching in cvs was always a bit of a black art to me. I always had to plan in advance, think twice and generally breathe heavily before I attempted to create a branch. The workflow would be

And then continue using that copy for your branch-specific changes. So the tag was the branch... or something like that. Anyway, you maintain a different tree for your HEAD too and will have to generally go through a lot of pain to merge patches from HEAD to branch or vice versa.

Now here's how you branch in git:

git branch mybranch

Yes, that is it. You have created a branch. Congratulations! Oh ok, you want to work on it?

git checkout mybranch

Do your foo and generally have fun with that branch. Oops, look! A patch that needs to go into HEAD:

git checkout master

And go ahead and apply your patch into HEAD. Time to push all the stuff into your public repository?

git push --all

And watch everything, including your branch changes get pushed seamlessly.

I'll say it again, this is one tool that seriously fits me like a glove. Simply awesome! The one thing left is now the merge back of the branches. I won't get there for another few weeks I guess, but from the docs, it seems as simple as:

git merge mybranch



I just did a merge now to see what git can do. I made some changes in master and decided to merge those changes into my new xmpp branch just for kicks. I have to admit that the merge did not have any conflicts, but here's how it went:

[siddhesh@spoyarek ayttm]$ git checkout xmpp
Switched to branch 'xmpp'
[siddhesh@spoyarek ayttm]$ git merge master
Merge made by recursive.
 libproxy/proxy.c                         |   41 ++++++++----------------------
 modules/aim-oscar/aim-oscar.c            |    7 +---
 modules/aycryption/select-keys.c         |    2 +-
 modules/importers/import_gnomeicu.c      |    1 -
 modules/importers/importicq.c            |    4 +--
 modules/importers/importlicq.c           |    1 -
 modules/irc/irc.c                        |   12 ++++----
 modules/irc/libirc/irc_message.c         |    4 +-
 modules/irc/libirc/libirc.c              |   10 +++---
 modules/irc/libirc/libirc.h              |    2 -
 modules/utility/autotrans.c              |    4 +-
 modules/utility/rainbow.c                |    4 +-
 modules/yahoo2/libyahoo2/libyahoo2.c     |    4 +--
 modules/yahoo2/libyahoo2/yahoo_httplib.c |    2 +-
 modules/yahoo2/yahoo.c                   |   16 +----------
 src/add_contact_window.c                 |    6 +++-
 src/edit_local_accounts.c                |    4 +-
 src/file_select.c                        |    1 -
 src/main.c                               |    4 +--
 src/message_parse.c                      |    3 --
 src/service.c                            |    2 +-
 src/smileys.c                            |    2 +-
 src/smileys.h                            |   12 ++++----
 src/sound.c                              |    6 +++-
 src/speech.c                             |    2 +-
 src/status.c                             |    5 ---
 src/trigger.c                            |    3 --
 27 files changed, 56 insertions(+), 108 deletions(-)

Yes, that is all! Here are the results of the merge. And here is the master branch