tags:

views:

173

answers:

1

When switching back from a local branch, I accidentally checked out a new branch, MASTER, and pushed it to origin. Now the repo has master and MASTER as branches. How do I safely rename MASTER and rebase it into master?

Thanks!

+3  A: 

There's really no need to rename it. Simply merge or rebase your new changes in MASTER onto master, then delete the MASTER branch.

  • git merge master MASTER will add a merge commit to master, along with the history of individual commits.

  • If you'd rather do a rebase, use git rebase master MASTER.

After either one of those, run git branch -d MASTER to delete your local MASTER branch. To delete the remote branch, run git push origin :MASTER (via this page). And be sure to push it all to origin afterwards.

Edit If you really do want to rename it, like if you maintain links to your topic branches, delete the remote branch, rename it locally using git branch -M MASTER foobar and push it to the remote.

John Douthat
Perfect! Thank you so much. I'm still learning git and really love what I've seen so far. I'll let you know how it goes.Thanks again!
Tricon
Yep. That worked perfectly. Thank you so much! You just resolved a major headache.
Tricon