-
Notifications
You must be signed in to change notification settings - Fork 6
/
.gitconfig
181 lines (159 loc) · 8.22 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
[user]
name = John Doe
email = john.doe@example.com
[core]
# This means that Git will process all text files and make sure that CRLF is replaced with LF when writing that file to the object database
# and turn all LF back into CRLF when writing out into the working directory.
autocrlf = true
[push]
# push the current branch to its upstream branch (synchronization only current branch)
# default = upstream
default = simple
[branch]
# If the option is true, then branches are tracked if they are remote, and not tracked if they are local
autosetupmerge = true
[color]
ui = auto
[color "status"]
added = green
changed = yellow
untracked = red
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold
[alias]
# init empty git repo, create README.md file and make initial commit
makegitrepo = !git init && touch README.md && git add . && git commit -m \"Initial commit\"
#LAZY VERSIONS OF BASIC COMMANDS
co = commit
s = status
st = status -sb
ch = checkout
br = branch
sta = stash -u
#BETTER VERSIONS OF BASIC COMMANDS
alias = !git config --list | grep 'alias\\.' | sed 's/alias\\.\\([^=]*\\)=\\(.*\\)/\\1 => \\2/' | grep -v 'alias'| awk 'BEGIN { FS = \"=>\" }{ printf(\"%-20s=>%s\\n\", $1,$2)}'|sort
difff = diff --color-words #Highlight changed words using only colors (without pluses and minuses)
llog = log --pretty=format:'%C(yellow)%h %Cred%ad %Cblue%an%Cgreen%d %Creset%s' --date=iso -25
ltree = log --oneline --all --graph --decorate
hist = log --pretty=format:'%Cred%h%Creset %C(bold blue)<%an>%Creset%C(yellow)%d%Creset %Cgreen(%cr)%Creset%n%w(80,8,8)%s' --graph
histfull = log --pretty=format:'%Cred%h%Creset %C(bold blue)<%an>%Creset%C(yellow)%d%Creset %Cgreen(%cr)%Creset%n%w(80,8,8)%s%n' --graph --name-status
changelog = log --pretty=format:'%Cgreen%d %Creset%s' --date=iso
changelogextended = log --pretty=format:'%C(yellow)%p..%h %C(white dim)%cd %<|(49,trunc)%an %C(reset)%s' --date=short --abbrev=8 --no-merges
unstage = reset HEAD --
bbranch = branch -v
branches = branch -avvl
mergenoff = merge --no-ff
mergenocommit = merge --no-commit
purr = pull --rebase
puff = pull --ff-only
rp = rev-parse --short=4
mergesquash = merge --squash
squash = "!f(){ git reset --soft HEAD~${1} && git commit --edit -m\"$(git log --format=%B --reverse HEAD..HEAD@{1})\"; };f"
#TAGS
tags = show-ref --tags
pushtags = push --tags
tagwithdate = !sh -c 'git tag "$0"_$(date "+%y-%m-%d_%H-%M-%S")'
lasttag = describe --abbrev=0 --tags
checkoutlasttag = !sh -c 'git checkout `git describe --abbrev=0 --tags`'
# Pushes given tag to remote 'origin' repo (or the remote passed as the second parameter)
publishtag = "!sh -c 'git push ${2:-origin} $1' -"
# Removes given tag from remote 'origin' repo (or the remote passed as the second parameter)
unpublishtag = "!sh -c 'git push ${2:-origin} :refs/tags/$1' -"
#what branches you have on origin, with info on who is guilty and how long ago. Useful for gitflow and feature branches in general. Requires fetch up-front.
showorigin = "!sh -c 'for branch in `git branch -r | grep -v HEAD`;do echo `git show -s --format=\"%Cred%ci %C(green)%h %C(yellow)%cr %C(magenta)%an %C(blue)\" $branch | head -n 1` \\\t$branch; done | sort -r'"
#get remote branches
trackallbranches = !sh -c "for branchname in `git branch -r `; do git branch --track $branchname; done" # get all remote branches
updateallbranches = !sh -c "for branchname in `git branch -r `; do git checkout $branchname ; git pull; done" # pull all remote branches
#Finds a filename in the git repository. Gives absolute location (from the git root).
find = !sh -c 'git ls-tree -r --name-only HEAD | grep --color $1' -
# Gets the current branch name (not so useful in itself, but used in other aliases)
branch-name = "!git rev-parse --abbrev-ref HEAD"
# Pushes the current branch to the remote "origin" (or the remote passed as the parameter) and set it to track the upstream branch
publish = "!sh -c 'git push -u ${1:-origin} $(git branch-name)' -"
# Deletes the remote version of the current branch from the remote "origin" (or the remote passed as the parameter)
unpublish = "!sh -c 'set -e; git push ${1:-origin} :$(git branch-name);git branch --unset-upstream $(git branch-name)' -"
# delete romote (on origin repo) and local branch
branchdelete = "!f(){ git push origin --delete ${1} && git branch -D ${1}; };f"
# Basic repo information / what was going on while you were away
whois = "!sh -c 'git log -i -1 --pretty=\"format::%an <%ae>\n\" --author=\"$1\"' -"
whatis = show -s --pretty='tformat::%h (%s, %ad)' --date=short
howmany = "!sh -c 'git log -a --pretty=oneline | wc -l'"
howmanybywhom = shortlog -sn
anychanges = !sh -c 'git fetch' && git log --oneline HEAD..origin/$1
anychangesonmaster = !sh -c 'git fetch' && git log --oneline HEAD..origin/master
whoischanging = !sh -c 'git shortlog HEAD..origin/$0'
whoischangingmaster = !sh -c 'git shortlog HEAD..origin/master'
# Alias: save - stage && save with provided message
# Example:
#
# git save This is very important commit...
# git save "This is very important commit..."
# git save This is commit --amend => the commit message will be: "This is commit --amend"
#
save = "!save() { git add -A; git commit -m "\"$*\""; }; save"
# Alias: amend - typical stage & commit with amend
# Example:
#
# git amend "This is very important commit..." => replace last commit
#
amend = "!amend() { git add -A; git commit --amend -m "\"$*\""; }; amend"
# Alias: backup - make git save and push to repo
# Example:
#
# git backup This is very important commit...
# git backup "This is very important commit..."
#
backup = "!backup() { git save "\"$*\""; git push; }; backup"
# Alias: stat - generate repo statistics
# Example:
#
# git stat
#
# Result: The working directory: 2.1G
# The git directory: 314M .git
# Commiters: 105
# Commits: 17388
stat = "!stat() { echo -n "The working directory: "; du -h -s --exclude=.git; echo -n "The git directory: "; du -h -s .git; echo -n "Commiters: "; git shortlog -s -n | wc -l; echo -n "Commits: "; git log --oneline | wc -l; }; stat"
# Alias: days - print dates of commits
# Example:
#
# git days
#
days = "!days() { git log --pretty=format:"%cd" --date=short | uniq; }; days"
updatefork = "!updatefork() { git fetch upstream; git checkout master; git rebase upstream/master; git push origin master; }; updatefork"
# Fetch PR from GitHub by number/id
fetchpr = "!sh -c 'git fetch origin pull/$0/head:pr/$0'"
#version for git below 2.1
issues = !sh -c 'git log --oneline $@ | egrep -o [A-Z]+-[0-9]+ | sort | uniq' -
## EDUCATIONAL ALIASES - TRAINING COMMANDS TO CREATE FAST COMMITS IN ORDER TO CHECK SOMETHING ON GIT / ETC. ##
# Alias: simple-commit - create file x.txt and commit with message "x"
# Example:
# git simple-commit x
simple-commit = !echo $1>$1.txt && git add -A && git commit -m "\"$@\"" && shift 1 && echo Simple comit done!
# Alias simple-commits - create file x.txt, y.txt and z.txt with commit messages "x", "y" and "z"
# Example:
# git simple-commits x y z
#
simple-commits = "!simpleCommits() { for name in \"$@\"; do git simple-commit $name; done; }; simpleCommits"
# Alias: simple-loop - create file x1.txt, x2.txt and x3.txt with commit messages "x1", "x2" and "x3"
# Example:
# simple-loop x 3
#
simple-loop = "!simpleLoop() { NAME=$1; i="1"; while [ $i -le $2 ]; do git simple-commit $NAME$i; i=$[$i+1]; done; }; simpleLoop"
# Alias: makebranches - create new branches (a, b and c) in current place
# Example:
# branches a b c
#
makebranches = "!makebranches() { for name in \"$@\"; do git branch $name; done; }; makebranches"
# Alias: clear - remove txt files and commit
# Example:
# git clear
#
#clear = "!clear() { rm *.txt; git save "Cleared!"; }; clear"