Created
November 13, 2013 17:14
-
-
Save chizmw/7452747 to your computer and use it in GitHub Desktop.
A bash script that ensures all my git aliases are set-up as I like them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# vim: ts=8 sts=4 et sw=4 sr sta | |
# only do the updates if this file is newer than our git config file | |
# (that means we've some something here) | |
if test $BASH_SOURCE -nt $HOME/.gitconfig; then | |
echo "[Updating git aliases...]"; | |
# exit immediately if we have the lockfile | |
if [ -f $HOME/.bashrcd.gitalias.lock ]; then | |
echo "[Another terminal is already updating the aliases. Aborting in this terminal.]"; | |
return; | |
fi | |
# 'lock' the update in case we're opening multiple terminals at the same | |
# time | |
if [ "`which git`" -a ! -f $HOME/.bashrcd.gitalias.lock ]; then | |
# exit immediately if we have the lockfile | |
if [ -f $HOME/.bashrcd.gitalias.lock ]; then | |
echo "[Another terminal is already updating the aliases. Aborting in this terminal.]"; | |
return; | |
fi | |
date > $HOME/.bashrcd.gitalias.lock; | |
git config --global alias.st status | |
git config --global alias.ci commit | |
git config --global alias.br branch | |
git config --global alias.co checkout | |
git config --global alias.df diff | |
git config --global alias.cpick cherry-pick | |
git config --global alias.pr "pull --rebase" | |
git config --global alias.undo "reset --soft HEAD^" | |
git config --global alias.clog "log --format=' * %s [%t]' -n 10" | |
git config --global alias.staged "diff --cached" | |
git config --global alias.unstaged "diff" | |
git config --global alias.amend "commit --amend" | |
git config --global alias.lg "log -p" | |
git config --global alias.lol "log --graph --decorate --pretty=oneline --abbrev-commit" | |
git config --global alias.lola "log --graph --decorate --pretty=oneline --abbrev-commit --all" | |
git config --global alias.ls "ls-files" | |
git config --global alias.refl "log -g --oneline 'HEAD@{now}' --date=relative" | |
git config --global alias.ca "commit --amend --reuse-message=HEAD" | |
git config --global alias.glog "log --pretty=oneline --topo-order --graph --abbrev-commit --decorate" | |
git config --global alias.tree "log --decorate --topo-order --graph --pretty=format:'%Cred%h%Creset%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold black)[%an]%Creset' --date=relative" | |
git config --global alias.tt "log --decorate --topo-order --graph --pretty=format:'%Cred%h%Creset%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold black)[%an]%Creset' --date=relative -n 10" | |
git config --global alias.tree "log --decorate --topo-order --graph --pretty=format:'%Cred%h %Cgreen[%cr] %C(bold black)<%an>%Creset%C(yellow)%d%Creset %s%Creset' --date=relative" | |
git config --global alias.tt "log --decorate --topo-order --graph --pretty=format:'%Cred%h %Cgreen[%cr] %C(bold black)<%an>%Creset%C(yellow)%d%Creset %s%Creset' --date=relative -n 10" | |
# http://stackoverflow.com/questions/2500296/can-i-make-fast-forwarding-be-off-by-default-in-git | |
if [ -d ./.git ]; then | |
git config branch.master.mergeoptions "--no-ff" | |
fi | |
# from http://mikewest.org/2011/04/a-quick-git-vim-workflow-tip | |
git config --global alias.fshow "! sh -c 'git show --pretty=\"format:\" --name-only \$1 | grep -v \"^$\" | uniq | sed -e \"s#^#\`git rev-parse --show-toplevel\`/#\"' -" | |
git config --global alias.vim "! sh -c 'vim \`git fshow \$1\`' -" | |
git config --global alias.mate "! sh -c 'mate \`git fshow \$1\`' -" | |
git config --global alias.edit "! sh -c '\$EDITOR \`git fshow \$1\`' -" | |
# from gianni | |
git config --global alias.cmp "diff -b --word-diff=color --word-diff-regex='[[:alnum:]_]+|[^[:space:]]'" | |
git config --global alias.cmplog "log -u -b --word-diff=color --word-diff-regex='[[:alnum:]_]+|[^[:space:]]'" | |
git config --global alias.cmpshow "show -u -b --word-diff=color --word-diff-regex='[[:alnum:]_]+|[^[:space:]]'" | |
git config --global alias.refl "log -g --oneline 'HEAD@{now}' --date=relative" | |
git config --global alias.st "status -bs" | |
git config --global alias.tracked "ls-tree --full-name -r --name-only HEAD" | |
git config --global alias.logc "log" | |
git config --global push.default current | |
# for git send-email; suppress warnings | |
git config --global sendemail.confirm auto | |
git config --global sendemail.chainreplyto false | |
rm $HOME/.bashrcd.gitalias.lock; | |
fi | |
fi | |
alias git_save_last_sha='_last_commit=$(git log --format=format:%H -n1)'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment