Swap a master and a feature branch

I started with poke's solution, but after pushing, the local branches were still tracking the old remote branches. To track the correct branches I just had to add the -u option for pushing.

git branch -m master newfeaturebranch
git branch -m feature1 master

git push -uf origin master
git push -u origin newfeaturebranch

It can be also done in two steps by first pushing and then adjusting the correct branch to track:

git push -f origin master
git push origin newfeaturebranch

git branch -u origin/master master
git branch -u origin/newfeaturebranch newfeaturebranch

You can rename branches:

git branch -m master newfeaturebranch
git branch -m feature1 master

Tags:

Branch

Git