Skip to content

Instantly share code, notes, and snippets.

@kampfgnu
Created April 24, 2013 08:19
Show Gist options
  • Save kampfgnu/5450536 to your computer and use it in GitHub Desktop.
Save kampfgnu/5450536 to your computer and use it in GitHub Desktop.
rename git branch
//First, in your working tree, locally rename master to something else.
git branch -m master old-dev
//Renaming a branch does work while you are on the branch, so there's no need to checkout something else.
//Then, locally rename the maintenance branch (2.63-branch) to master:
git branch -m 2.63-branch master
//Now, time to mess with the remote. Just in case you screw up, you might want to make sure you have a current backup. First, //delete the remote's master:
git push origin :master
//And now, give the remote your new master (When creating a new branch, the refs/heads/ prefix is needed on the remote side. If the branch already exists only the branch name is required on the remote side.):
git push origin master:refs/heads/master
//... and your now-renamed old master:
git push origin old-dev:refs/heads/old-dev
//Finally, delete the old name of your maintenance branch to prevent confusion:
git push origin :2.63-branch
Clients will now get the 'new' master branch when they pull.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment