What Git aliases are in your .bashrc?

I asked our contributors for their favorite and most useful Git aliases so that you could take advantage of their ideas.
Register or Login to like
Women in computing and open source v5

kris krüg

Many open source users love a good Bash alias and are usually happy to show off a particularly robust .bashrc file when given the chance. If you're a frequent user of Git, you might benefit from a few Git aliases mixed in with your other Bash aliases. Alternately, you can create aliases specific to Git with this git config command. This example sets the git co command to git checkout.

$ git config --global alias.co checkout

I asked our contributors for their favorite and most useful Git aliases so that you could take advantage of their ideas. Here are their suggestions.


Here's an easy way to see just the most recent log entry:

git config alias.last 'log -1 HEAD'

Opensource.com author Sachin Patil uses hist for reviewing logs:

log --pretty=format:'%h %ai [%an] %s%d' --graph

Sachin creates this Bash alias for pull requests:

# github pull request. 
# Usage: git pr <REMOTE> <PR_ID> <branch>

pr="\!sh -c 'git fetch $1 pull/$2/head:$3 && git checkout $3' -"

The git diff command is helpful for all kinds of comparisons, but sometimes all you really want is the file name of what's changed. Kristen Pol creates an alias to shorten the --name-only option:

git diff --name-only

Kristen says, "We typically have a lot of development happening simultaneously, so knowing the most recent commit across all branches is handy." Here's a command Kristen aliases for that purpose:

git branch --remotes --verbose --sort=-committerdate

Everybody appreciates a fresh start. This is Kristen's alias for wiping out a branch, leaving it fresh and clean:

alias gitsuperclean='git reset --hard; git clean --force -d -x'

Custom filter-repo command

Chris has been using a "third-party" Git command called git-filter-repo.

Chris explains the alias. "Ever want to pull a specific directory out of a larger Git repository and make it its own, separate repo, while keeping all the Git history? That's exactly what filter-repo does."

Your aliases

What Git command do you use so often that you alias it? Do you use Bash aliases or Git aliases, or a mix of both? Tell us in the comments!

AmyJune headshot.
AmyJune is an experienced community manager, mentor, public speaker, and inclusion advocate. While her roots are in Drupal, she also contributes regularly to the Linux and Accessibility communities.


Couple of nice aliases, thanks for sharing!

I'm a sucker for colors and compacted info so I have this for logs:

lol = log --graph --decorate --pretty=format:'%C(yellow)%h %C(green)%cd %C(cyan)[%an] %Creset%s' --date=format:'%F %T'

The "[%an]" is the newest addition thanks to this article :)

I use a lot 'git status', so my favourite alias is:
git config --global alias.s status

1.) To stash everything, whether or not it is staged for commit:

alias gstu='git stash --include-untracked'

2.) To restore everything you've stashed:

alias gstp='git stash pop'

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.