Today I Learned

hashrocket A Hashrocket project

Renaming Git Branches

Git branches can evolve into roles they weren't meant to fill. An example is an application with a branch called 'good-master', where all current development is happening, despite the existence of a stale branch called 'master'. We can fix this!

One solution is to merge 'master' into 'good-master'. But that can be tricky if you don't want a lot of the changes.

You can also rename the branches. In our case, 'good-master' is the true master branch, so 'master' should be deleted (or preserved, if you prefer).

$ git branch -m master master-old # rename master to master-old
$ git push origin :master # delete master at origin
$ git push origin master-old # create master-old at origin (or delete it)

$ git checkout good-master
$ git branch -m good-master master # rename good-master to master
$ git push origin :good-master # delete good-master
$ git push origin master # create new master

Next, change your default Github branch to the new master. Anyone new the project will find a more logical repo to work with. Existing developers can reset their local repo with:

$ git fetch origin
$ git reset --hard origin/master
See More #git TILs