DEV Community

Conlin Durbin
Conlin Durbin

Posted on

Your favorite `git` aliases?

What git aliases do you use? Why do you like them?

Latest comments (16)

Collapse
 
ryanmaynard profile image
Ryan Maynard

Here are mine:


alias gb='git branch'
alias gs='git status'
alias ga='git add'
alias gc='git commit'
alias gl='git log'
alias glo='git log --pretty=oneline'
alias glu="git log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short"
alias glg="git log --decorate --graph --abbrev-commit --date=relative"
alias gh='git checkout'
alias gt='git tag'
alias grs='git reset'
alias grv='git revert'
alias gm='git merge'
alias gd='git diff'
alias gp='git push'
alias gpo='git push origin'
alias gob='git checkout -b'
alias gh='cat .git/HEAD'
alias grgu='git remote get-url'

alias gbb="git for-each-ref --sort=-committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'"
alias gbbb="git for-each-ref --sort=-committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'"


Collapse
 
gayanhewa profile image
Gayan Hewa

I used to love the alias's that ship with Oh-my-zsh, then I found magit

Collapse
 
jef profile image
Jef LeCompte

alias gpc='git push --set-upstream origin "$(git-branch-current 2> /dev/null)"'

if you don't have anything, this would suffice alone. i always forget how to push my new branch to remote...

Collapse
 
hozefaj profile image
Hozefa

Here is my list of git alias

# git aliases
alias gc='git checkout'
alias gcm='git commit -m'
alias gs='git status'
alias ga='git add --all'
alias gp='git pull --rebase'
alias gb='git branch -vv'
alias gr='git remote -v'
alias grt='git reset --hard'
alias gpub='git push origin publish'
alias grp='git rebase publish'
alias gdev='git push origin dev'
alias gd='git branch -D'
alias gm='git merge'
alias gmx='git merge -X theirs'
alias gh='git push hozefa'
alias gk='gitk &'
alias gda='git branch | grep -v "develop" | grep -v "release" | xargs git branch -D'
alias gf='git fetch'
alias gl='git log -3'
# cleans all branches locally that have already been merged.
alias gcmb="git branch --merged | grep -Ev '(^\*|develop)' | xargs git branch -d"
Collapse
 
mattiaslundberg profile image
Mattias Lundberg

Shorthand for using git (bash/zsh alias):

alias g=git

Undo the last commit:

undo = reset --soft HEAD^

Get a summary of commits since yesterday (useful during standups):

standup = !"git log --reverse --branches --since=$(if [[ "Mon" == "$(date +%a)" ]]; then echo "friday"; else echo "yesterday"; fi) --author=$(git config --get user.email) --format=format:'%C(cyan) %ad %C(yellow)%h %Creset %s %Cgreen%d' --date=local"

Push to origin:

pp = push origin

Force push to origin:

ppf = push origin --force-with-lease

Pretty log:

lol = log --pretty=format:"%C(yellow)%h\\ %Cblue%G?%Cred%d\\ %Creset%s%Cgreen\\ (%cr)%Cblue\\ [%cn]" --decorate --graph

Collapse
 
5422m4n profile image
Sven Kanoldt • Edited

one for lazy remote tracking of the current branch

grep track ~/.gitconfig
    track = "!git branch --set-upstream-to=origin/`git symbolic-ref --short HEAD`"
Collapse
 
moopet profile image
Ben Sinclair
Collapse
 
wh0am1 profile image
Carlos Aguilar

This is a must have on my .bashrc:

alias gc="git clone"
alias gp="git push"
alias gl="git pull"
alias gf="git fetch"
alias gd="git diff"
alias gco="git checkout"
alias gsb="git status -sb"
alias gba="git branch -a"
alias grv="git remote -v"
alias gaa="git add --all"
alias ga="git add"
alias gcmsg="git commit -m"
alias gm="git merge"
alias gri="git rebase -i"
alias gcount="git shortlog -sn"
alias glol="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'"
alias glog="git log --oneline --decorate --graph"

These are from the oh-my-zsh git plugin:
github.com/robbyrussell/oh-my-zsh/...

Collapse
 
zhuangya profile image
zhuangya

alias.hug merge --ff-only

Collapse
 
eddycorderol profile image
Eddy Cordero

ud = "!f() { git checkout develop && git pull origin develop; }; f"
lbranch = "!f() { git rev-parse --abbrev-ref @{-1}; }; f"
udrcb = "!f() { git ud && git checkout $(git lbranch) && git rebase develop; }; f"