git.plugin.zsh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. # Aliases
  2. alias g='git'
  3. compdef g=git
  4. alias gst='git status'
  5. compdef _git gst=git-status
  6. alias gd='git diff'
  7. compdef _git gd=git-diff
  8. alias gdc='git diff --cached'
  9. compdef _git gdc=git-diff
  10. alias gdt='git diff-tree --no-commit-id --name-only -r'
  11. compdef _git gdc=git diff-tree --no-commit-id --name-only -r
  12. alias gl='git pull'
  13. compdef _git gl=git-pull
  14. alias gup='git pull --rebase'
  15. compdef _git gup=git-fetch
  16. alias gp='git push'
  17. compdef _git gp=git-push
  18. alias gd='git diff'
  19. gdv() { git diff -w "$@" | view - }
  20. compdef _git gdv=git-diff
  21. alias gdt='git difftool'
  22. alias gc='git commit -v'
  23. compdef _git gc=git-commit
  24. alias gc!='git commit -v --amend'
  25. compdef _git gc!=git-commit
  26. alias gca='git commit -v -a'
  27. compdef _git gc=git-commit
  28. alias gca!='git commit -v -a --amend'
  29. compdef _git gca!=git-commit
  30. alias gcmsg='git commit -m'
  31. compdef _git gcmsg=git-commit
  32. alias gco='git checkout'
  33. compdef _git gco=git-checkout
  34. alias gcm='git checkout master'
  35. alias gr='git remote'
  36. compdef _git gr=git-remote
  37. alias grv='git remote -v'
  38. compdef _git grv=git-remote
  39. alias grmv='git remote rename'
  40. compdef _git grmv=git-remote
  41. alias grrm='git remote remove'
  42. compdef _git grrm=git-remote
  43. alias grset='git remote set-url'
  44. compdef _git grset=git-remote
  45. alias grup='git remote update'
  46. compdef _git grset=git-remote
  47. alias grbi='git rebase -i'
  48. compdef _git grbi=git-rebase
  49. alias grbc='git rebase --continue'
  50. compdef _git grbc=git-rebase
  51. alias grba='git rebase --abort'
  52. compdef _git grba=git-rebase
  53. alias gb='git branch'
  54. compdef _git gb=git-branch
  55. alias gba='git branch -a'
  56. compdef _git gba=git-branch
  57. alias gbr='git branch --remote'
  58. alias gcount='git shortlog -sn'
  59. compdef gcount=git
  60. alias gcl='git config --list'
  61. alias gcp='git cherry-pick'
  62. compdef _git gcp=git-cherry-pick
  63. alias glg='git log --stat --max-count=10'
  64. compdef _git glg=git-log
  65. alias glgg='git log --graph --max-count=10'
  66. compdef _git glgg=git-log
  67. alias glgga='git log --graph --decorate --all'
  68. compdef _git glgga=git-log
  69. alias glo='git log --oneline --decorate --color'
  70. compdef _git glo=git-log
  71. alias glog='git log --oneline --decorate --color --graph'
  72. compdef _git glog=git-log
  73. alias gss='git status -s'
  74. compdef _git gss=git-status
  75. alias ga='git add'
  76. compdef _git ga=git-add
  77. alias gap='git add --patch'
  78. alias gm='git merge'
  79. compdef _git gm=git-merge
  80. alias grh='git reset HEAD'
  81. alias grhh='git reset HEAD --hard'
  82. alias gclean='git reset --hard && git clean -dfx'
  83. alias gwc='git whatchanged -p --abbrev-commit --pretty=medium'
  84. # Sign and verify commits with GPG
  85. alias gcs='git commit -S'
  86. compdef _git gcs=git-commit
  87. alias gsps='git show --pretty=short --show-signature'
  88. compdef _git gsps=git-show
  89. # Sign and verify tags with GPG
  90. alias gts='git tag -s'
  91. compdef _git gts=git-tag
  92. alias gvt='git verify-tag'
  93. compdef _git gvt=git verify-tag
  94. #remove the gf alias
  95. #alias gf='git ls-files | grep'
  96. alias gpoat='git push origin --all && git push origin --tags'
  97. alias gmt='git mergetool --no-prompt'
  98. compdef _git gm=git-mergetool
  99. alias gg='git gui citool'
  100. alias gga='git gui citool --amend'
  101. alias gk='gitk --all --branches'
  102. alias gsts='git stash show --text'
  103. alias gsta='git stash'
  104. alias gstp='git stash pop'
  105. alias gstd='git stash drop'
  106. # Will cd into the top of the current repository
  107. # or submodule.
  108. alias grt='cd $(git rev-parse --show-toplevel || echo ".")'
  109. # Git and svn mix
  110. alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk'
  111. compdef git-svn-dcommit-push=git
  112. alias gsr='git svn rebase'
  113. alias gsd='git svn dcommit'
  114. #
  115. # Will return the current branch name
  116. # Usage example: git pull origin $(current_branch)
  117. #
  118. function current_branch() {
  119. if [ ! -d .git ]; then return; fi
  120. ref=$(git symbolic-ref HEAD 2> /dev/null) || \
  121. ref=$(git rev-parse --short HEAD 2> /dev/null) || return
  122. echo ${ref#refs/heads/}
  123. }
  124. function current_repository() {
  125. if [ ! -d .git ]; then return; fi
  126. ref=$(git symbolic-ref HEAD 2> /dev/null) || \
  127. ref=$(git rev-parse --short HEAD 2> /dev/null) || return
  128. echo $(git remote -v | cut -d':' -f 2)
  129. }
  130. # these aliases take advantage of the previous function
  131. alias ggpull='git pull origin $(current_branch)'
  132. compdef ggpull=git
  133. alias ggpur='git pull --rebase origin $(current_branch)'
  134. compdef ggpur=git
  135. alias ggpush='git push origin $(current_branch)'
  136. compdef ggpush=git
  137. alias ggpnp='git pull origin $(current_branch) && git push origin $(current_branch)'
  138. compdef ggpnp=git
  139. # Pretty log messages
  140. function _git_log_prettily(){
  141. if ! [ -z $1 ]; then
  142. git log --pretty=$1
  143. fi
  144. }
  145. alias glp="_git_log_prettily"
  146. compdef _git glp=git-log
  147. # Work In Progress (wip)
  148. # These features allow to pause a branch development and switch to another one (wip)
  149. # When you want to go back to work, just unwip it
  150. #
  151. # This function return a warning if the current branch is a wip
  152. function work_in_progress() {
  153. if $(git log -n 1 2>/dev/null | grep -q -c "\-\-wip\-\-"); then
  154. echo "WIP!!"
  155. fi
  156. }
  157. # these alias commit and uncomit wip branches
  158. alias gwip='git add -A; git ls-files --deleted -z | xargs -r0 git rm; git commit -m "--wip--"'
  159. alias gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1'
  160. # these alias ignore changes to file
  161. alias gignore='git update-index --assume-unchanged'
  162. alias gunignore='git update-index --no-assume-unchanged'
  163. # list temporarily ignored files
  164. alias gignored='git ls-files -v | grep "^[[:lower:]]"'