Skip to content

Instantly share code, notes, and snippets.

@iand
Created April 26, 2016 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iand/23af1a408d7eec29117fa260a397f02d to your computer and use it in GitHub Desktop.
Save iand/23af1a408d7eec29117fa260a397f02d to your computer and use it in GitHub Desktop.
Git Aliases
# Show modified files in last commit:
dl = "!git ll -1"
# Show a diff last commit:
dlc = diff --cached HEAD^
# List oneline commits showing relative dates:
ld = log --pretty=format:"%C(yellow)%h\\ %Cred%d\\ %Creset%s\\ %C(green)(%ad)%Cblue\\ [%cn]" --decorate --date=relative
# List oneline commits showing dates
lds = log --pretty=format:"%C(yellow)%h\\ %Cred%d\\ %Creset%s\\ %C(green)(%ad)%Cblue\\ [%cn]" --decorate --date=short
# List commits showing changed files
ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat
# List commits in short form, with colors and branch/tag annotations.
ls = log --pretty=format:"%C(yellow)%h\\ %Cred%d\\ %Creset%s\\ %C(green)(%ad)%Cblue\\ [%cn]" --decorate --date=relative
# List all git aliases
la = "!git config -l | grep alias | cut -c 7-"
# Suggestions from http://gggritso.com/human-git-aliases
branches = branch -a
tags = tag
stashes = stash list
# List all changes by me since yesterday
yesterday = log --since yesterday --author ian
# Brief status
st = status -sb
# Commit all changes with a message
c = commit -am
# Add all files
a = add -A
## Just a shorter alias
co = checkout
# undo the last commit
undo = reset --soft HEAD~1
# Edit the last commit
amend = commit --amend
# Discard modifications made to a file
discard = checkout --
# Unstage a file
unstage = reset -q HEAD --
# Start a new feature branch by updating master then create a new branch then push it to origin
new = "!f() { git checkout master && git fetch origin && git merge --ff origin/master && git checkout -b $1 master && git push -u origin $1; }; f"
# Merge from master
up = !git fetch origin && git rebase -p origin/master
# Interactive rebase to master
ir = !git rebase -i origin/master
# Commit changes to origin
done = !git fetch origin && git rebase -p origin/master && git push
# remove a branch both locally and remotely when it is no longer needed
rmb = "!f() { git branch -D $1 && git push origin :$1; }; f"
# list all local merged branches that have been deleted on remote
lsm = "!f() { git branch --merged | grep -v \"\\*\"; }; f"
# remove all local merged branches that have been deleted on remote
rmm = "!f() { git branch --merged | grep -v \"\\*\" | xargs -n 1 git branch -d; }; f"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment