Git Branches
Contents
Renaming Branches
A local-only branch can be renamed easily. Given a repository named my-repo:
# ensure that you are in the repository directory and checked into the target branch cd path/to/my-repo git checkout master # to rename branch 'master' to 'dev'... git branch -m master dev
To rename a remote branch, first follow the above process. The remaining steps can produce errors.
git push -u origin dev git push origin --delete master
If git returns an error like ! [remote rejected] master (deletion of the current branch prohibited), then you need to adjust the HEAD of the remote repository. This determines what branch a new repository clone will start on. The 'default' branch cannot be deleted for obvious reasons.
Keeping with the example above, access the bare remote repository my-repo.git and edit my-repo.git/HEAD such that it points to the new branch's head.
ref: refs/heads/dev
Valid values correspond to the branch references in my-repo.git/refs/heads/.