-
Notifications
You must be signed in to change notification settings - Fork 3
/
gitconfig
75 lines (56 loc) · 3.77 KB
/
gitconfig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Global config suitable for /etc/gitconfig
[pull]
rebase = true
[diff]
# https://github.com/git/git/blob/e5272d304af3528163cd5faa822f88086448ae57/Documentation/diff-options.txt#L311-L312
wsErrorHighlight = all
[alias]
# Log aliases
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cd) (%an)%Creset' --abbrev-commit --date=human
llg = log --graph --pretty=format:'%Cred%H%Creset -%C(yellow)%d%Creset %s %Cgreen(%cd) (%an)%Creset' --date=human
# Last 5 commits (!git llg -n 5)
llg5 = log --graph --pretty=format:'%Cred%H%Creset -%C(yellow)%d%Creset %s %Cgreen(%cd)%Creset' --date=human -n 5
# Last 5 commits (!git lg -n 5)
lg5 = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cd) (%an)%Creset' --abbrev-commit --date=human -n 5
# Last commit
l = log --name-status HEAD^..HEAD --summary
# Git pull but with fast forwarding only allowed. Prevent merge commits.
# http://stackoverflow.com/questions/15316601/why-is-git-pull-considered-harmful
pf = pull --ff-only
# Git pull with rebase. Saves having to do a fetch followed by a rebase.
# http://gitolite.com/tips/git-pull--rebase.html
# https://coderwall.com/p/7aymfa
pr = pull --rebase
# Git pr but autostashing as well.
prs = "!f() { [[ `git ls-files -m | wc -l` != 0 ]] && s=true ; if [ \"$s\" = true ]; then git stash; fi; git pr ; if [ \"$s\" = true ]; then git stash pop ; fi }; f"
# Unpushed changes
unpushed = "!f() { [[ -z \"$1\" ]] && o=origin || o=$1 ; GIT_CURRENT_BRANCH=$(git rev-parse --symbolic-full-name --abbrev-ref HEAD) ; if [ -n \"$(git ls-remote --heads $o $GIT_CURRENT_BRANCH)\" ]; then git log $o/$GIT_CURRENT_BRANCH..$GIT_CURRENT_BRANCH --oneline ;else echo \"Branch does not exist in remote\" ;fi }; f"
# Diff with whitespace ignored
dw = diff --ignore-space-at-eol --ignore-all-space --ignore-space-change
# Show tracking branches
trackbranch = for-each-ref --format='%(refname:short) <- %(upstream:short)' refs/heads
# Interactive stash
interactivestash = stash push --patch
# Stash listing
sl=stash list --pretty=format:'%C(yellow)%gd(%cr)%Creset: %gs'
# Short git remote / status / branch
s = status -sb
r = remote -v
b = branch -v
bb = branch -av
# Show the commit a tag is pointing at.
tagcommit = "!f() { git rev-parse --verify $1^{commit}; }; f"
# Show what changes there are in the tracking branch.
changesupstream = "!f() { [[ -z \"$1\" ]] && o=origin || o=$1 ; GIT_CURRENT_BRANCH=$(git rev-parse --symbolic-full-name --abbrev-ref HEAD) ; if [ -n \"$(git ls-remote --heads $o $GIT_CURRENT_BRANCH)\" ]; then git remote update $o ; echo Changes... ; git llg `git symbolic-ref --short HEAD`..$o/`git symbolic-ref --short HEAD` ;else echo \"Branch does not exist in remote\" ;fi }; f"
# Restore a delete file
restore = "!f() { local rev=$(git rev-list -n 1 HEAD -- \"$1\") ; if [ -z \"$rev\" ]; then echo \"Unable to find reference to restore\" ; return 1 ; else git checkout $rev^ -- \"$1\" ; fi }; f"
# Print out current aliases
alias = !git config -l | grep alias
# Fetch remote pull request
fetchpr = "!f() { [[ ! -z \"$2\" ]] && o=origin || o=$1 ; shift ; then git fetch origin pull/$1/head:pr-$1 }; f"
# Uncommit
uncommit = reset --soft HEAD~1
# Ignore
ignore = "!f() { echo -e \"\n\" >> .gitignore ; for i in \"$@\" ; do echo \"$i\" >> .gitignore ; done; }; f"
# Squash last commits: https://gist.github.com/jbub/5766366
fixup = "!f(){ git reset --soft HEAD~${1-1} && git commit --amend -C HEAD; };f"