Add the following to your ~/.bashrc
:
alias g='git'
Install bash-completion
brew install bash-completion
Add the following to your ~/.bash_profile
:
if [ -f $(brew --prefix)/etc/bash_completion ]; then
source $(brew --prefix)/etc/bash_completion
fi
Create ~/.gitexcludes
file and paste:
.DS_Store
Add the following aliases into your ~/.gitconfig
file:
[alias]
a = add
f = fetch
rb = rebase
me = merge
co = checkout
br = branch
ci = commit
cm = !git add -A && git commit -m
amend = commit -a --amend
rm = "!f() { git branch -D ${1-develop}; }; f"
s = status
cob = checkout -b
cp = cherry-pick
last = log -1 HEAD
l = log --oneline
g = log --oneline --graph
cl = clean -fxd
grep = !git ls-files | grep -i
gs = diff --staged
# compare two branches
cmp = "!f() { git log --no-merges ${1}..; }; f"
# pull with rebase & removes not-existing remote-tracking branches
up = !git pull --rebase --prune
# quick save
save = !git add -A && git commit -m 'SAVEPOINT'
undo = reset HEAD~1 --mixed
# reset with undo using reflog :)
wipe = !git add -A && git commit -qm 'WIPE SAVEPOINT' && git reset HEAD~1 --hard
# delete alread-merged branches
rmb = "!f() { git branch --merged ${1} | grep -v ${1} | xargs -n 1 git branch -d; }; f"
# list unpushed commits
unpushed = log --branches --not --remotes --color --graph --abbrev-commit \
--pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset%s %Cgreen(%cr) %C(bold blue)%Creset'
alias = !git config --list | grep 'alias\\.' \
| sed 's/alias\\.\\([^=]*\\)=\\(.*\\)/\\1\\\t /' | sort
- Enable git templates:
git config --global init.templatedir '~/.git-templates'
- Create a directory to hold the global hooks:
mkdir -p ~/.git-templates/hooks
- Add the following hook into your
~/.git-templates/hooks/pre-commit
. It prevents from pushing commit containing word#DANGER#
.
#!/bin/sh
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
fi
marker="#DANGER#"
exec 1>&2
if test $(git diff --cached -z $against | grep $marker | wc -c) != 0
then
cat <<\EOF
Error: Invalid debug markers in code:
EOF
echo `git diff --name-only --cached -z $against -G $marker`
exit 1
fi
- Make sure the hook is executable:
chmod +x ~/.git-templates/hooks/post-commit
- Re-initialize git in each existing repo:
git init
What about Windows ?