8 Jan 2011 rkrishnan   » (Journeyer)

git - renaming branches

I was working on a project recently, which involved cloning another git repository and adding my own changes into it. After I cloned it, I forgot to create and switch to the new branch and do my changes there. So all my changes were in the ‘master’ branch. I rather wanted to have my changes in my own branch. git makes these things trivial. All you have to do is rename your current master:

$ git branch -m <old-branch-name> <new-branch-name>
$ git branch (should show the new name)
Now, do a git log and find out which is the commit before you started making the change and do:
$ git checkout -b <old-branch-name> <commit-sha1>
That’s it and you have the whole thing as you wanted it to be.

Thanks to my friend Anand for the tip on the -m option to git branch. Most git gems seem to be deep embedded in those switches of the sub commands of git.

Syndicated 2010-01-24 08:00:00 from Ramakrishnan Muthukrishnan

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!