September 10, 2015

My Favorite Git Aliases

edit

If you’re like me, you like to find patterns in your work and turn them into aliases and shortcuts in the terminal. I thought I’d share with you my current Git aliases, explaining a few along the way.

For starters, you’ll want to add these aliases to your .gitconfig file.

[alias]
  br = branch
  brm = branch --merged
  brnm = branch --no-merged
  ci = commit
  co = checkout
  copl = "!f() { git checkout $1 && git pull --rebase origin $1; }; f"
  df = diff
  lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
  mg = merge
  st = status
  plo = pull --rebase origin
  pho = push origin
  plod = pull --rebase origin dev
  phod = push origin dev
  plos = pull --rebase origin stage
  phos = push origin stage
  plom = pull --rebase origin master
  phom = push origin master
  reaper-nokill = remote prune --dry-run origin
  reaper = remote prune origin

Most of these aliases are self explanatory, but let’s go through some of the less common ones.

brm

Using the branch --merged command will give you a list of branches merged into the branch you’re currently on. It’s counterpart branch --no-merged does exactly the opposite. These commands are great for cleaning up merged branches.

copl

This is a function that takes a branch name for an argument. It first checks out that branch, and then runs a git pull --rebase on that branch. I found myself constantly checking out a branch and pulling it immediately, so I turned it into one alias.

lg

This is a prettier log format. It will actually create the branch structure in the terminal.

reaper

Sometimes you need your local git to forget about remote branches that no longer exist. This is where pruning comes into play. When I first wrote this alias, it was repr for “remote prune”. Phonetically, that sounded like “reaper” and given that I’m slashing branches from git, it seemed appropriate to rename the alias after our friendly harbinger of death.

So there you have it. Hope this Git aliases help you out. Leave some of your favorites in the comments below.


Liked the post?
Give the author a dopamine boost with a few "beard strokes". Click the beard up to 50 times to show your appreciation.
Need help with your software problems?

My team and I are ready to help you. Hire Agathist to build your next great project or to improve one of your existing ones.

Get in touch
Kyle Shevlin's face, which is mostly a beard with eyes

Kyle Shevlin is the founder & lead software engineer of Agathist, a software development firm with a mission to build good software with good people.

Agathist
Good software by good people.
Visit https://agath.ist to learn more
Sign up for my newsletter
Let's chat some more about TypeScript, React, and frontend web development. Unsubscribe at any time.
Logo for Data Structures and Algorithms
Data Structures and Algorithms
Check out my courses!
If you enjoy my posts, you might enjoy my courses, too. Click the button to view the course or go to Courses for more information.