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.