Learn Docker With My Newest Course

Dive into Docker takes you from "What is Docker?" to confidently applying Docker to your own projects. It's packed with best practices and examples. Start Learning Docker →

Use git push origin HEAD to Quickly Push the Checked Out Branch

use-git-push-origin-head-to-quickly-push-the-checked-out-branch.jpg

When pushing commits to a remote branch, instead of typing out the branch name you can use HEAD as a shortcut.

Quick Jump:

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.

Never Miss a Tip, Trick or Tutorial

Like you, I'm super protective of my inbox, so don't worry about getting spammed. You can expect a few emails per year (at most), and you can 1-click unsubscribe at any time. See what else you'll get too.



Comments