Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# Working with branches
# Get the current branch name (not so useful in itself, but used in
# other aliases)
branch-name = "!git rev-parse --abbrev-ref HEAD"
# Push the current branch to the remote "origin", and set it to track
# the upstream branch
publish = "!git push -u origin $(git branch-name)"
# Delete the remote version of the current branch
unpublish = "!git push origin :$(git branch-name)"
# Delete a branch and recreate it from master — useful if you have, say,
# a development branch and a master branch and they could conceivably go
# out of sync
recreate = "!f() { [[ -n $@ ]] && git checkout \"$@\" && git unpublish && git checkout master && git branch -D \"$@\" && git checkout -b \"$@\" && git publish; }; f"
# Fire up your difftool (e.g. Kaleidescope) with all the changes that
# are on the current branch.
code-review = difftool origin/master...
# Given a merge commit, find the span of commits that exist(ed) on that
# branch. Again, not so useful in itself, but used by other aliases.
merge-span = "!f() { echo $(git log -1 $2 --merges --pretty=format:%P | cut -d' ' -f1)$1$(git log -1 $2 --merges --pretty=format:%P | cut -d' ' -f2); }; f"
# Find the commits that were introduced by a merge
merge-log = "!git log `git merge-span .. $1`"
# Show the changes that were introduced by a merge
merge-diff = "!git diff `git merge-span ... $1`"
# As above, but in your difftool
merge-difftool = "!git difftool `git merge-span ... $1`"
# Interactively rebase all the commits on the current branch
rebase-branch = "!git rebase -i `git merge-base master HEAD`"
# Working with files
# Unstage any files that have been added to the staging area
unstage = reset HEAD
# Show changes that have been staged
diffc = diff --cached
# Mark a file as "assume unchanged", which means that Git will treat it
# as though there are no changes to it even if there are. Useful for
# temporary changes to tracked files
assume = update-index --assume-unchanged
# Reverse the above
unassume = update-index --no-assume-unchanged
# Show the files that are currently assume-unchanged
assumed = "!git ls-files -v | grep ^h | cut -c 3-"
# Checkout our version of a file and add it
ours = "!f() { git checkout --ours $@ && git add $@; }; f"
# Checkout their version of a file and add it
theirs = "!f() { git checkout --theirs $@ && git add $@; }; f"
# Delete any branches that have been merged into master
# See also:
delete-merged-branches = "!git co master && git branch --merged | grep -v '\\*' | xargs -n 1 git branch -d"
cp = cherry-pick
st = status -s
cl = clone
ci = commit
co = checkout
br = branch
diff = diff --word-diff
dc = diff --cached
s = status
sml = ls-files -m
sm = status -uno
b = branch
ba = branch -a -v -v
bs = !git-branch-status
bsi = !git-branch-status -i
ci = commit
co = checkout
d = diff -C
ds = diff -C --stat
dsp = diff -C --stat -p
dw = diff -C --color-words
p = pull
alias gst='git status'
alias gl='git pull'
alias gp='git push'
alias gd='git diff | mate'
alias gau='git add --update'
alias gc='git commit -v'
alias gca='git commit -v -a'
alias gb='git branch'
alias gba='git branch -a'
alias gco='git checkout'
alias gcob='git checkout -b'
alias gcot='git checkout -t'
alias gcotb='git checkout --track -b'
alias glog='git log'
alias glogp='git log --pretty=format:"%h %s" --graph'
# git
alias ga='git add'
alias gb='git branch'
alias gc='git commit'
alias gca='git commit -a'
alias gcam='git commit -a -m'
alias gce='git commit -e'
alias gcm='git commit -m'
alias gco='git checkout'
alias gd='git diff'
alias gdc='git diff --cached'
alias gpom='git push origin master'
alias gr='git remote'
alias gs='git status'
#useful stuff for git
export EDITOR='vim -f'
export PAGER='less'
function branchname { git branch 2> /dev/null | grep -e '\* ' | sed 's/^..\(.*\)/[\1]/'; }
alias ga='git add'
alias gps='git push'
alias gl='git log'
alias gs='git status'
alias gd='git diff'
alias gcm='git commit -m'
alias gcam='git commit -am'
alias gca='git commit -a'
alias gb='git branch'
alias gco='git checkout'
alias gra='git remote add'
alias grr='git remote rm'
alias gpl='git pull'
alias gcl='git clone'
alias gsb='git show-branch'
# commandline prompt displays current branch
export PS1='\[\e[1;36m\][\t] \h:\w$(branchname) \[\e[0m\]'
# .gitconfig in your repo, user or system folder
ci = commit
cim = commit -m
st = status
commit-all = !git add -A && git commit # long version
cia = !git add -A && git commit # add/update everything and commit
ciam = !git add -A && git commit -m
add-all = add -A
aa = add -A
this = !git init && git add . && git commit -m \"initial commit\" #
unstage = reset HEAD -- # Unstage a specific file
last = log -1 HEAD # Show last commit
lg = log --oneline -20 # Show last 20 logs as one liners without pagination.
copy-out = !sh -c 'git show $0:"$1" > "$2"' # Checkout a file from a previous commit into a new filename
alias ls='ls -p'
alias ll='ls -la'
alias c='clear'
alias v='vim'
alias x="exit"
alias ..='cd ..'
alias ...='cd ../../../'
alias ....='cd ../../../../'
alias .....='cd ../../../../'
st = status
di = diff
co = checkout
ci = commit
br = branch
sta = stash
graph = log --decorate --oneline --graph --branches --date-order
lg = log --graph --pretty=format:'%C(yellow)%h%Creset -%C(yellow)%d%Creset %s %C(green)(%cr)%Creset %Cred<%an>%Creset' --abbrev-commit --date=relative --date-order
today = !git log --author=$(git config --since=yesterday
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.