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

    Reference

  2. oh-my-bash

  3. Oh My Zsh
  4. Oh My Zsh Plugins