Git: rename a branch locally and remotely

11 Jul

git checkout master
git push origin HEAD:newBranchName (1) Create a new branch remotely
git branch newBranchName (2) Create a new branch locally
git checkout newBranchName (3) Checkout the new branch
git pull origin oldBranchName (4) Remote old ==> Local new branch
git push origin newBranchName (5) Local new branch ==> Remote new
git branch – – set-upstream newBranchName origin/newBranchName (6) set up local branch to track remote branch
git branch –d oldBranchName (7) delete local old branch
git push origin : oldBranchName (8) delete remote old branch

Note I: the local branch can be renamed by:

git branch -m oldBranchName newBranchName

Note II: step (1), (2) and (6) can be combined into a single command:

git branch newBranchName origin/newBranchName
Leave a comment

Posted by on July 11, 2012 in Programming



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

%d bloggers like this: