<p>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.</p>

<p>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?</p>

<p>Thanks for all the (quick) answers! They're all good.</p>

[{'answer_id': 21897, 'author': 'olliej', 'author_id': 784, 'author_profile': 'https://Stackoverflow.com/users/784', 'pm_score': 3, 'selected': False, 'text': '<p>This is relatively easy:</p>\n\n<pre><code>git checkout -b fake_master master # fake_master now points to the same commit as master\ngit branch -D master               # get rid of incorrect master\ngit checkout -b master real_master # master now points to your actual master\ngit checkout master                # optional -- switch on to your master branch\n</code></pre>\n'}, {'answer_id': 21905, 'author': 'T Percival', 'author_id': 954, 'author_profile': 'https://Stackoverflow.com/users/954', 'pm_score': 4, 'selected': False, 'text': '<p>Start on <code>master</code>, create a branch called <code>in-progress</code>, then reset <code>master</code> to an earlier commit.</p>\n\n<pre><code>$ git branch in-progress\n$ git reset --hard HEAD^\n</code></pre>\n'}, {'answer_id': 21932, 'author': 'Greg Hewgill', 'author_id': 893, 'author_profile': 'https://Stackoverflow.com/users/893', 'pm_score': 8, 'selected': True, 'text': '<p>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:</p>\n\n<pre><code>git branch -m master crap_work\ngit branch -m previous_master master\n</code></pre>\n'}, {'answer_id': 24012, 'author': 'Brian Riehman', 'author_id': 2063, 'author_profile': 'https://Stackoverflow.com/users/2063', 'pm_score': 5, 'selected': False, 'text': "<p>I think you should consider a different development strategy to prevent issues like this.  One that seems to work best for me is to never do development directly on my master branch.  Regardless of the changes I'm making, I always create a new branch for new code:</p>\n\n<pre>\ngit checkout -b topic/topic_name master\n</pre>\n\n<p>From there, I can push out the changes to public repositories:</p>\n\n<pre>\ngit push pu topic/topic_name\n</pre>\n\n<p>or eventually just merge it back in with my master branch:</p>\n\n<pre>\ngit checkout master && git merge topic/topic_name\n</pre>\n\n<p>If you truly need to go back to an older point in time and set that as your master, you can rename the current branch to something else and then check out an older version to be your master:</p>\n\n<pre>\n git branch -m master junk\n git co -b master old_sha1_value\n</pre>\n"}, {'answer_id': 12021187, 'author': 'Penghe Geng', 'author_id': 814145, 'author_profile': 'https://Stackoverflow.com/users/814145', 'pm_score': 0, 'selected': False, 'text': '<p>This will set your master to any point in one step:</p>\n\n<pre><code>git checkout -B master new_point\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/21848', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2427/']