-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit.zsh
184 lines (176 loc) · 6.09 KB
/
git.zsh
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
181
182
183
184
# Git aliases
#
# Note: Some of these are Zsh defaults with the `git` plugin.
# I explicitly added them here for reference, since some are overridden.
#
# It's also nice to have these for when the shell isn't Zsh (e.g. in MinGW).
#
alias g='git'
alias gst='git status'
alias gl='git log'
alias glp='git log --patch'
alias gld='git log --pretty=fuller `# Show commit date along with author date`'
alias gss='git log -S `# Find commits with string added/removed in diff`'
alias gsg='git log -G `# Find commits with regex string anywhere in changed lines`'
alias grl='git reflog'
alias gco='git checkout'
alias gcob='gb; git checkout -b'
alias gcm='git checkout main'
alias gcmr='git checkout master'
alias gcs='git checkout stable'
alias gcd='git checkout dev'
alias gcdp='git checkout develop'
alias gcdt='git checkout development'
alias gcl='git clone --recursive'
alias gb='git --no-pager branch'
alias gbu='gb -u origin/`branch` `branch`' # Set upstream
alias ga='git add'
alias gaa='git add --all; git status'
alias gaaa=gaa
alias gc='git commit -v'
alias gce='git commit -v --allow-empty'
alias gc!='git commit -v --allow-empty --amend'
alias gc@='git commit -v --allow-empty --amend --no-edit'
gcw() {
# "Work in progress" sort of commit.
git commit -m "🚧 $@"
}
alias gp='echo "gps: git push, gpl: git pull"'
alias gps='git push'
alias gpso='git push origin'
alias gpsoh='git push origin HEAD'
alias gf='git fetch'
alias gpl='git pull'
alias gploh='git pull origin HEAD'
alias gplr='git pull --rebase'
alias gd='git diff'
alias gdc='git diff --cached'
alias gds='git diff --stat'
alias gdm='git diff main'
alias gdmr='git diff master'
alias gm='git merge'
alias gmm='git merge main'
alias gmmr='git merge master'
alias gmd='git merge dev'
alias gmdp='git merge develop'
alias gmdt='git merge development'
alias gsta='git stash'
alias gstl='git stash list'
alias gsts='git stash save'
alias gstp='git stash pop'
alias gstd='echo "Dangerous! Try gsta drop instead."'
alias gstc='echo "Dangerous! Try gsta clear instead."'
alias grs='git reset'
alias grsh='git reset HEAD'
alias grsh1='git reset HEAD^'
alias grhs1='grsh1'
alias grsH='git reset --hard'
alias grsHom='git reset --hard origin/main'
alias grsHomr='git reset --hard origin/master'
grhhdir() {
# grhh for each subdirectory
ls -d */ | awk '{print $NF}' | xargs -n1 sh -c 'cd $0 && pwd && git reset HEAD --hard'
}
alias grt='git revert'
alias grb='git rebase'
alias grbm='git rebase main'
alias grbmr='git rebase master'
alias grbd='git rebase dev'
alias grbdp='git rebase develop'
alias grbdt='git rebase development'
alias grbc='git rebase --continue'
alias grba='git rebase --abort'
alias gcp='git cherry-pick'
alias gcpc='git cherry-pick --continue'
alias gcps='git cherry-pick --skip'
alias gcpa='git cherry-pick --abort'
alias gcpm='gcp -m 1'
alias gfp='git format-patch'
alias gap='git apply `# For single patches`'
alias gam='git am `# "Apply Mailbox" for a series of patches`'
alias gamc='git am --continue'
alias gams='git am --skip'
alias gama='git am --abort'
alias grm='git rm'
alias grem='git remote'
grema() {
#echo "Use 'hub fetch $1' instead" # No longer works in 2023?
#return
local repo
if [ -z $2 ]; then
repo=`basename $(git rev-parse --show-toplevel)`
else
repo=$2
fi
echo "Adding $1/${repo}"
git remote add $1 [email protected]:$1/${repo}.git
}
alias grup='git remote update'
alias gt='git --no-pager tag'
alias grp='git rev-parse'
alias grph='git rev-parse HEAD'
alias grls='git rev-list'
alias grlsc='git rev-list --count'
alias gas='echo "Consider --skip-worktree instead!"; git update-index --assume-unchanged'
alias gnas='echo "Consider --no-skip-worktree instead!"; git update-index --no-assume-unchanged'
alias gsw='git update-index --skip-worktree'
alias gig='gsw'
alias gnsw='git update-index --no-skip-worktree'
alias gbs='git bisect'
alias gbss='git bisect start'
alias gbsg='git bisect good'
alias gbsb='git bisect bad'
alias gbsr='git bisect reset'
alias gsm='git submodule'
alias gsmu='git submodule update'
alias gcl='git clone --recursive'
alias gcfg='git config'
alias gcfgg='git config --global'
alias gplkc='git pull kc HEAD'
alias gpskc='git push -f kc HEAD'
alias recent='git branch --sort=-committerdate | head'
# alias gh='git help' # Conflicts with `gh` GitHub CLI
# See also https://github.com/cli/cli/blob/trunk/docs/gh-vs-hub.md
alias hh='hub help'
alias hb='hub browse'
alias hf='hub fetch'
alias hc='hub clone'
alias hgc='hub gist create --browse'
alias branch='git rev-parse --abbrev-ref HEAD'
alias ref='git rev-parse --short HEAD'
diffs() {
git log $1..origin/main --author=cooperka
}
gcof() {
if [ $1 ]; then
git fetch
git checkout -B $1 origin/$1
fi
}
pushtag() {
if [ $1 ]; then
gt $1
git push origin tags/$1
fi
}
# Memory jogs
alias upstream='echo "git branch --set-upstream-to origin/branchName OR git branch -u origin/branchName OR git push -u origin branchName"'
alias bisect='echo "gbs start\ngbs good fd0a623\ngbs bad 256d850\ngbs good\ngbs bad\ngbs reset"'
pullify() {
echo "#git config --global --add remote.origin.fetch \"+refs/heads/*:refs/remotes/origin/*\""
echo "git config --global --add remote.origin.fetch \"+refs/pull/*/head:refs/remotes/origin/pr/*\""
echo "git config --global --add remote.origin.fetch \"+refs/merge-requests/*/head:refs/remotes/origin/mr/*\""
echo "#git config --global --add remote.kc.fetch \"+refs/heads/*:refs/remotes/kc/*\""
echo "git config --global --add remote.kc.fetch \"+refs/pull/*/head:refs/remotes/kc/pr/*\""
echo "git config --global --add remote.kc.fetch \"+refs/merge-requests/*/head:refs/remotes/kc/mr/*\""
echo "vim ~/.gitconfig"
}
git-patch() {
echo "git diff > fix.patch"
echo "git format-patch HEAD^ --stdout > fix.patch"
echo "git format-patch HEAD^ -o fix/"
echo "git apply --stat fix.patch # Preview the changes"
echo "git am fix.patch # Meaning 'Apply Mailbox', optionally with --signoff (-s)"
}
alias patch-git=git-patch
alias git-prune-branches="echo \"git for-each-ref --format='%(refname:short)' 'refs/heads/foo*' | xargs git branch -D # Remove any local branch starting with 'foo'; or replace foo* with foo/** to delete any branch under the foo directory.\""