Git Rename Branch : local & remote

If you have named a branch incorrectly and pushed this to the remote repository follow these steps to rename the branch name both locally and on server.

1. Rename your local git branch.
If you already have branch checked out which you want to rename

git branch -m newName</code>

If you are on a different branch

git branch -m oldName newName

2. Delete the old-name remote branch and push the new-name local branch

git push origin :oldName newName

3. Reset the upstream branch for the new-name local branch.
Switch to the branch and then:

git push origin -u newName


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s