Use git push origin HEAD to Quickly Push the Checked Out Branch
When pushing commits to a remote branch, instead of typing out the branch name you can use HEAD as a shortcut.
I use git
from the command line most of the time and when working on branches
that I plan to push and make a PR out of, I found myself typing git push origin 123-hello-world
or whatever the branch name happens to be to push
changes.
I’ve configured my shell’s prompt to show the git branch but long branch names get truncated with ...
so it’s not always easy to
copy the branch name.
It’s a little embarrassing because I only recently discovered you can run git push origin HEAD
as a shortcut to push the current branch that you have
checked out. This is great because it no longer means needing to remember
individual branch names for each PR or project you’re working on. It’s
consistent and short to type.
You can use git pull origin HEAD
too!
I like this option more than setting a custom upstream since most branches I work on are usually short lived PR branches, but I do add these for long lived branches.
The video below goes over these commands.
# Demo Video
Timestamps
- 0:21 – What you might do before this
- 1:44 – Just use git push origin HEAD
How do you quickly push PR branches? Let me know below.