Skip to content

Instantly share code, notes, and snippets.

@cmattoon
Created November 11, 2015 19:21
Show Gist options
  • Save cmattoon/cae95b87a69c3da86e72 to your computer and use it in GitHub Desktop.
Save cmattoon/cae95b87a69c3da86e72 to your computer and use it in GitHub Desktop.
git aliases
## Some useful git aliases
## To apply aliases globally (for all repos on your computer), copy into ~/.gitconfig
## To add an alias to one repository only, add it to /path/to/repo/.git/config
##
## ALIASES THAT MENTION BRANCH/ORIGIN NAMES ('master', 'develop', 'origin', 'upstream') should be
## double-checked before adding to anything other than our repos, since these are relative terms.
## If you create a new repo, for example, that doesn't have a 'develop' branch, or 'origin' is not what
## you expect, it can mess things up. Most of them are safe for general use though.
##
[alias]
# List all aliases
la = "!git config -l | grep alias | cut -c 7-"
# Fetch from origin and upstream, merge upstream/develop into local/develop
pu = !"git fetch origin -v; git fetch upstream -v; git merge upstream/develop"
# Pretty log
ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate
# Pretty log (with files)
ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat
# One-line commits with dates
lds = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short
# Plain text (for piping to other commands)
lnc = log --pretty=format:"%h\\ %s\\ [%cn]"
# Show the history of a file, with diffs
filelog = log -u
fl = log -u
# Find files and content inside files
f = "!git ls-files | grep -i"
# Fix commits!
# Take all uncommitted and un-staged changes in the current working directory and add them
# to the previous commit, amending it before pushing the change up.
# POTENTIALLY DANGEROUS! You should probably stage first, then run 'git commit --amend -C HEAD'
cia = commit -a --amend -C HEAD
## SVN shortcuts
st = status
cl = clone
ci = commit
co = checkout
br = branch
diff = diff --word-diff
diffc = diff --cached
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment