Skip to content

Instantly share code, notes, and snippets.

@O-I
Last active August 29, 2015 14:14
Show Gist options
  • Save O-I/e1cb37b2ccd5f3aca82c to your computer and use it in GitHub Desktop.
Save O-I/e1cb37b2ccd5f3aca82c to your computer and use it in GitHub Desktop.
[TIx 5] Rename an unpushed local git branch

Here's a scenario I found myself in recently. I was looking to fix a small bug in an open source project I admire. I forked the repo, checked out a feature branch, and got to work getting myself lost in the land of Minitest.

I have a habit of making small, atomic commits so I tend to run git status frequently. On doing so, I noticed something like this:

$ git status
On branch fix-tpyo
Changes not staged for commit:
  # snip

Oh no! The branch name has a typo in it. I hate it when stuff like this pops up when I'm in the middle of a commit. Luckily, git makes it really easy to change the name of an unpushed local branch if you know how. Just run:

$ git branch -m <old_branch_name> <new_branch_name>

or if you're in the branch you'd like to rename:

$ git branch -m <new_branch_name>

So, using my example:

$ git branch -m fix-typo
$ git status
On branch fix-typo
Changes not staged for commit:
  # snip

Yay! One less (minor but super annoying) thing standing in the way of making that pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment