git.plugin.zsh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 gl='git pull'
  9. compdef _git gl=git-pull
  10. alias gup='git pull --rebase'
  11. compdef _git gup=git-fetch
  12. alias gp='git push'
  13. compdef _git gp=git-push
  14. alias gd='git diff'
  15. gdv() { git diff -w "$@" | view - }
  16. compdef _git gdv=git-diff
  17. alias gc='git commit -v'
  18. compdef _git gc=git-commit
  19. alias gc!='git commit -v --amend'
  20. compdef _git gc!=git-commit
  21. alias gca='git commit -v -a'
  22. compdef _git gc=git-commit
  23. alias gca!='git commit -v -a --amend'
  24. compdef _git gca!=git-commit
  25. alias gco='git checkout'
  26. compdef _git gco=git-checkout
  27. alias gcm='git checkout master'
  28. alias gr='git remote'
  29. compdef _git gr=git-remote
  30. alias grv='git remote -v'
  31. compdef _git grv=git-remote
  32. alias grmv='git remote rename'
  33. compdef _git grmv=git-remote
  34. alias grrm='git remote remove'
  35. compdef _git grrm=git-remote
  36. alias grset='git remote set-url'
  37. compdef _git grset=git-remote
  38. alias grup='git remote update'
  39. compdef _git grset=git-remote
  40. alias grbi='git rebase -i'
  41. compdef _git grbi=git-rebase
  42. alias grbc='git rebase --continue'
  43. compdef _git grbc=git-rebase
  44. alias grba='git rebase --abort'
  45. compdef _git grba=git-rebase
  46. alias gb='git branch'
  47. compdef _git gb=git-branch
  48. alias gba='git branch -a'
  49. compdef _git gba=git-branch
  50. alias gcount='git shortlog -sn'
  51. compdef gcount=git
  52. alias gcl='git config --list'
  53. alias gcp='git cherry-pick'
  54. compdef _git gcp=git-cherry-pick
  55. alias glg='git log --stat --max-count=5'
  56. compdef _git glg=git-log
  57. alias glgg='git log --graph --max-count=5'
  58. compdef _git glgg=git-log
  59. alias glgga='git log --graph --decorate --all'
  60. compdef _git glgga=git-log
  61. alias glo='git log --oneline'
  62. compdef _git glo=git-log
  63. alias gss='git status -s'
  64. compdef _git gss=git-status
  65. alias ga='git add'
  66. compdef _git ga=git-add
  67. alias gm='git merge'
  68. compdef _git gm=git-merge
  69. alias grh='git reset HEAD'
  70. alias grhh='git reset HEAD --hard'
  71. alias gclean='git reset --hard && git clean -dfx'
  72. alias gwc='git whatchanged -p --abbrev-commit --pretty=medium'
  73. alias gf='git ls-files | grep'
  74. alias gpoat='git push origin --all && git push origin --tags'
  75. alias gmt='git mergetool --no-prompt'
  76. compdef _git gm=git-mergetool
  77. alias gg='git gui citool'
  78. alias gga='git gui citool --amend'
  79. alias gk='gitk --all --branches'
  80. alias gss='git stash show --text'
  81. # Will cd into the top of the current repository
  82. # or submodule.
  83. alias grt='cd $(git rev-parse --show-toplevel || echo ".")'
  84. # Git and svn mix
  85. alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk'
  86. compdef git-svn-dcommit-push=git
  87. alias gsr='git svn rebase'
  88. alias gsd='git svn dcommit'
  89. #
  90. # Will return the current branch name
  91. # Usage example: git pull origin $(current_branch)
  92. #
  93. function current_branch() {
  94. ref=$(git symbolic-ref HEAD 2> /dev/null) || \
  95. ref=$(git rev-parse --short HEAD 2> /dev/null) || return
  96. echo ${ref#refs/heads/}
  97. }
  98. function current_repository() {
  99. ref=$(git symbolic-ref HEAD 2> /dev/null) || \
  100. ref=$(git rev-parse --short HEAD 2> /dev/null) || return
  101. echo $(git remote -v | cut -d':' -f 2)
  102. }
  103. # these aliases take advantage of the previous function
  104. alias ggpull='git pull origin $(current_branch)'
  105. compdef ggpull=git
  106. alias ggpur='git pull --rebase origin $(current_branch)'
  107. compdef ggpur=git
  108. alias ggpush='git push origin $(current_branch)'
  109. compdef ggpush=git
  110. alias ggpnp='git pull origin $(current_branch) && git push origin $(current_branch)'
  111. compdef ggpnp=git
  112. # Pretty log messages
  113. function _git_log_prettily(){
  114. if ! [ -z $1 ]; then
  115. git log --pretty=$1
  116. fi
  117. }
  118. alias glp="_git_log_prettily"
  119. compdef _git glp=git-log