git.plugin.zsh 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #
  2. # Functions
  3. #
  4. # The name of the current branch
  5. # Back-compatibility wrapper for when this function was defined here in
  6. # the plugin, before being pulled in to core lib/git.zsh as git_current_branch()
  7. # to fix the core -> git plugin dependency.
  8. function current_branch() {
  9. git_current_branch
  10. }
  11. # Pretty log messages
  12. function _git_log_prettily(){
  13. if ! [ -z $1 ]; then
  14. git log --pretty=$1
  15. fi
  16. }
  17. compdef _git _git_log_prettily=git-log
  18. # Warn if the current branch is a WIP
  19. function work_in_progress() {
  20. if $(git log -n 1 2>/dev/null | grep -q -c "\-\-wip\-\-"); then
  21. echo "WIP!!"
  22. fi
  23. }
  24. #
  25. # Aliases
  26. # (sorted alphabetically)
  27. #
  28. alias g='git'
  29. alias ga='git add'
  30. alias gaa='git add --all'
  31. alias gapa='git add --patch'
  32. alias gau='git add --update'
  33. alias gav='git add --verbose'
  34. alias gap='git apply'
  35. alias gb='git branch'
  36. alias gba='git branch -a'
  37. alias gbd='git branch -d'
  38. alias gbda='git branch --no-color --merged | command grep -vE "^(\+|\*|\s*(master|develop|dev)\s*$)" | command xargs -n 1 git branch -d'
  39. alias gbD='git branch -D'
  40. alias gbl='git blame -b -w'
  41. alias gbnm='git branch --no-merged'
  42. alias gbr='git branch --remote'
  43. alias gbs='git bisect'
  44. alias gbsb='git bisect bad'
  45. alias gbsg='git bisect good'
  46. alias gbsr='git bisect reset'
  47. alias gbss='git bisect start'
  48. alias gc='git commit -v'
  49. alias gc!='git commit -v --amend'
  50. alias gcn!='git commit -v --no-edit --amend'
  51. alias gca='git commit -v -a'
  52. alias gca!='git commit -v -a --amend'
  53. alias gcan!='git commit -v -a --no-edit --amend'
  54. alias gcans!='git commit -v -a -s --no-edit --amend'
  55. alias gcam='git commit -a -m'
  56. alias gcsm='git commit -s -m'
  57. alias gcb='git checkout -b'
  58. alias gcf='git config --list'
  59. alias gcl='git clone --recurse-submodules'
  60. alias gclean='git clean -id'
  61. alias gpristine='git reset --hard && git clean -dfx'
  62. alias gcm='git checkout master'
  63. alias gcd='git checkout develop'
  64. alias gcmsg='git commit -m'
  65. alias gco='git checkout'
  66. alias gcount='git shortlog -sn'
  67. alias gcp='git cherry-pick'
  68. alias gcpa='git cherry-pick --abort'
  69. alias gcpc='git cherry-pick --continue'
  70. alias gcs='git commit -S'
  71. alias gd='git diff'
  72. alias gdca='git diff --cached'
  73. alias gdcw='git diff --cached --word-diff'
  74. alias gdct='git describe --tags $(git rev-list --tags --max-count=1)'
  75. alias gds='git diff --staged'
  76. alias gdt='git diff-tree --no-commit-id --name-only -r'
  77. alias gdw='git diff --word-diff'
  78. function gdv() { git diff -w "$@" | view - }
  79. compdef _git gdv=git-diff
  80. alias gf='git fetch'
  81. alias gfa='git fetch --all --prune'
  82. alias gfo='git fetch origin'
  83. alias gfg='git ls-files | grep'
  84. alias gg='git gui citool'
  85. alias gga='git gui citool --amend'
  86. function ggf() {
  87. [[ "$#" != 1 ]] && local b="$(git_current_branch)"
  88. git push --force origin "${b:=$1}"
  89. }
  90. compdef _git ggf=git-checkout
  91. function ggfl() {
  92. [[ "$#" != 1 ]] && local b="$(git_current_branch)"
  93. git push --force-with-lease origin "${b:=$1}"
  94. }
  95. compdef _git ggfl=git-checkout
  96. function ggl() {
  97. if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
  98. git pull origin "${*}"
  99. else
  100. [[ "$#" == 0 ]] && local b="$(git_current_branch)"
  101. git pull origin "${b:=$1}"
  102. fi
  103. }
  104. compdef _git ggl=git-checkout
  105. function ggp() {
  106. if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
  107. git push origin "${*}"
  108. else
  109. [[ "$#" == 0 ]] && local b="$(git_current_branch)"
  110. git push origin "${b:=$1}"
  111. fi
  112. }
  113. compdef _git ggp=git-checkout
  114. function ggpnp() {
  115. if [[ "$#" == 0 ]]; then
  116. ggl && ggp
  117. else
  118. ggl "${*}" && ggp "${*}"
  119. fi
  120. }
  121. compdef _git ggpnp=git-checkout
  122. function ggu() {
  123. [[ "$#" != 1 ]] && local b="$(git_current_branch)"
  124. git pull --rebase origin "${b:=$1}"
  125. }
  126. compdef _git ggu=git-checkout
  127. alias ggpur='ggu'
  128. alias ggpull='git pull origin "$(git_current_branch)"'
  129. alias ggpush='git push origin "$(git_current_branch)"'
  130. alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)'
  131. alias gpsup='git push --set-upstream origin $(git_current_branch)'
  132. alias ghh='git help'
  133. alias gignore='git update-index --assume-unchanged'
  134. alias gignored='git ls-files -v | grep "^[[:lower:]]"'
  135. alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk'
  136. alias gk='\gitk --all --branches'
  137. alias gke='\gitk --all $(git log -g --pretty=%h)'
  138. alias gl='git pull'
  139. alias glg='git log --stat'
  140. alias glgp='git log --stat -p'
  141. alias glgg='git log --graph'
  142. alias glgga='git log --graph --decorate --all'
  143. alias glgm='git log --graph --max-count=10'
  144. alias glo='git log --oneline --decorate'
  145. alias glol="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'"
  146. alias glols="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --stat"
  147. alias glod="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset'"
  148. alias glods="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short"
  149. alias glola="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --all"
  150. alias glog='git log --oneline --decorate --graph'
  151. alias gloga='git log --oneline --decorate --graph --all'
  152. alias glp="_git_log_prettily"
  153. alias gm='git merge'
  154. alias gmom='git merge origin/master'
  155. alias gmt='git mergetool --no-prompt'
  156. alias gmtvim='git mergetool --no-prompt --tool=vimdiff'
  157. alias gmum='git merge upstream/master'
  158. alias gma='git merge --abort'
  159. alias gp='git push'
  160. alias gpd='git push --dry-run'
  161. alias gpf='git push --force-with-lease'
  162. alias gpf!='git push --force'
  163. alias gpoat='git push origin --all && git push origin --tags'
  164. alias gpu='git push upstream'
  165. alias gpv='git push -v'
  166. alias gr='git remote'
  167. alias gra='git remote add'
  168. alias grb='git rebase'
  169. alias grba='git rebase --abort'
  170. alias grbc='git rebase --continue'
  171. alias grbd='git rebase develop'
  172. alias grbi='git rebase -i'
  173. alias grbm='git rebase master'
  174. alias grbs='git rebase --skip'
  175. alias grev='git revert'
  176. alias grh='git reset'
  177. alias grhh='git reset --hard'
  178. alias groh='git reset origin/$(git_current_branch) --hard'
  179. alias grm='git rm'
  180. alias grmc='git rm --cached'
  181. alias grmv='git remote rename'
  182. alias grrm='git remote remove'
  183. alias grs='git restore'
  184. alias grset='git remote set-url'
  185. alias grss='git restore --source'
  186. alias grt='cd "$(git rev-parse --show-toplevel || echo .)"'
  187. alias gru='git reset --'
  188. alias grup='git remote update'
  189. alias grv='git remote -v'
  190. alias gsb='git status -sb'
  191. alias gsd='git svn dcommit'
  192. alias gsh='git show'
  193. alias gsi='git submodule init'
  194. alias gsps='git show --pretty=short --show-signature'
  195. alias gsr='git svn rebase'
  196. alias gss='git status -s'
  197. alias gst='git status'
  198. # use the default stash push on git 2.13 and newer
  199. autoload -Uz is-at-least
  200. is-at-least 2.13 "$(git --version 2>/dev/null | awk '{print $3}')" \
  201. && alias gsta='git stash push' \
  202. || alias gsta='git stash save'
  203. alias gstaa='git stash apply'
  204. alias gstc='git stash clear'
  205. alias gstd='git stash drop'
  206. alias gstl='git stash list'
  207. alias gstp='git stash pop'
  208. alias gsts='git stash show --text'
  209. alias gstall='git stash --all'
  210. alias gsu='git submodule update'
  211. alias gsw='git switch'
  212. alias gswc='git switch -c'
  213. alias gts='git tag -s'
  214. alias gtv='git tag | sort -V'
  215. alias gtl='gtl(){ git tag --sort=-v:refname -n -l "${1}*" }; noglob gtl'
  216. alias gunignore='git update-index --no-assume-unchanged'
  217. alias gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1'
  218. alias gup='git pull --rebase'
  219. alias gupv='git pull --rebase -v'
  220. alias gupa='git pull --rebase --autostash'
  221. alias gupav='git pull --rebase --autostash -v'
  222. alias glum='git pull upstream master'
  223. alias gwch='git whatchanged -p --abbrev-commit --pretty=medium'
  224. alias gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign -m "--wip-- [skip ci]"'