Renaming branches

TL;DR below

Today I wanted to move my metruzanca/metruzanca.github.io to a different repository for two reasons:

  • First, so that I could host my portfolio without all my other gh-pages defaulting to zbest.dev/<repo name>
  • I don’t like master being the only folder allowed for gh-pages and instead having a dev repo in place of master.

So I decided to move clone my repo and then push it to a new repository metruzanca/zbest.dev.

After pulling i needed to rename a few things:

master -> gh-pages
dev -> master

Renaming a branch locally is easy enough

git checkout old_branch_name

git branch -m new_branch_name

I Initially thought that would be enough, but when i pushed to the new repo i noticed that when using commands like git status that the now gh-pages branch was still referencing origin/master (which was now a different branch aka what was origin/dev). As you can imagine this, will create some havoc. So I realized that i needed update the upstream reference.

This is also easy enough

git push origin -u branch_name

For those curious, the -u flag does is the same as the —set-upstream flag. Which should look more familiar if you’ve ever run git push without specifying the origin name and remote branch. Git will be helpful and give you a copy-paste command to set the remote reference for that branch so that you can then use git push in the future while on that branch.

TL;DR

# Checkout the branch you wanna rename
git checkout old_branch_name
# Rename the branch
git branch -m new_branch_name
# Update the upstream reference
git push origin -u branch_name
Contact
EMAIL: ved.acnaz@mas
PHONE: 3566 664 848 1+
Made with by Sam Zanca