tags:

views:

5113

answers:

4

There may be more than one way to ask this question, so here's a desciption of the problem. I was working on master and committed some stuff and then decided I wanted to put that work on hold. I backed up a few commits and then branched from before I started my crap work. Practically this works fine, I just now have a different branch as my main development branch. I'm wondering how I could change things around so I'm working on master again but it doesn't have my junk work and said work is on a different branch.

Some ways this could be asked/solved: How do I rename my master branch to something else and then rename something else to master? How do I back up master and then cause all commits I've backed up past to be on a different branch?

Thanks for all the (quick) answers! They're all good.

+2  A: 

This is relatively easy:

git checkout -b fake_master master # fake_master now points to the same commit as master
git branch -D master               # get rid of incorrect master
git checkout -b master real_master # master now points to your actual master
git checkout master                # optional -- switch on to your master branch
olliej
+3  A: 

Start on master, create a branch called in-progress, then reset master to an earlier commit.

$ git branch in-progress
$ git reset --hard HEAD^
Ted Percival
I see no reason for this to have been voted down. I did it myself a few times, before I learned about branch -m and realized that master wasn't immutably tied as the permanent name of a branch.
skiphoppy
+31  A: 

In addition to the other comments, you may find the -m (move) switch to git-branch helpful. You could rename your old master to something else, then rename your new branch to master:

git branch -m master crap_work
git branch -m previous_master master
Greg Hewgill
+12  A: 
Brian Riehman
That's a good policy. And come to think of it, I have seen that practiced elsewhere. Thanks.
Rimian