git.zsh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # preferred git shortcuts, not in the git plugin
  2. #compare the provided version of git to the version installed and on path
  3. #prints 1 if input version <= installed version
  4. #prints -1 otherwise
  5. function git_compare_version() {
  6. local INPUT_GIT_VERSION=$1;
  7. local INSTALLED_GIT_VERSION
  8. INPUT_GIT_VERSION=(${(s/./)INPUT_GIT_VERSION});
  9. INSTALLED_GIT_VERSION=($(command git --version 2>/dev/null));
  10. INSTALLED_GIT_VERSION=(${(s/./)INSTALLED_GIT_VERSION[3]});
  11. for i in {1..3}; do
  12. if [[ $INSTALLED_GIT_VERSION[$i] -lt $INPUT_GIT_VERSION[$i] ]]; then
  13. echo -1
  14. return 0
  15. fi
  16. done
  17. echo 1
  18. }
  19. POST_1_8_3_GIT=$(git_compare_version "1.8.3")
  20. unset -f git_compare_version
  21. # As of git 1.8.3 decorations can be coloured automatically according to what
  22. # they are i.e. tags, branches, etc.
  23. if [[ $POST_1_8_3_GIT -gt 0 ]]; then
  24. DECO_COLOUR='%C(auto)'
  25. else
  26. DECO_COLOUR='%Cgreen'
  27. fi
  28. GIT_LOG_FORMAT='"format:%C(yellow)%h %Creset%ad %Cblue%an:'$DECO_COLOUR'%d %Creset%s"'
  29. alias ga.='git add -A .'
  30. alias gap='git add -p'
  31. alias gs='git status'
  32. alias gd='git diff'
  33. alias gds='git diff --staged'
  34. alias gcob='git checkout -b'
  35. alias gf='git fetch --all --tags && git fetch --all --prune'
  36. alias gbd='git branch -D'
  37. alias gbv='git branch -v'
  38. alias gbav='git branch -av'
  39. # standard log with train tracks
  40. alias gl='git log --graph --date=short --pretty='$GIT_LOG_FORMAT
  41. alias gla='gl --all'
  42. # concise, branch and tag log with train tracks (some merge commits unavoidable)
  43. alias glb='gl --simplify-by-decoration'
  44. alias glh='gl | head'
  45. alias glp='git log --graph --patch'
  46. # useful when you want to have a visual on file changes
  47. alias gls='git log --graph --stat'
  48. # search through history for particular text
  49. alias glS='git log -S'
  50. alias gr='git reset'
  51. alias grh='git reset --hard'
  52. alias grs='git reset --soft'
  53. alias grb='git rebase'
  54. # useful for finding parent commit for a given commit hash
  55. alias gsr='git show --format=raw'
  56. # git submodule management
  57. alias gsm='git submodule'
  58. alias gsmup='git submodule sync && git submodule update --init'
  59. alias gsmpull='git submodule foreach git pull origin master'
  60. # useful if you forget to setup tracking for a new branch when checking out.
  61. alias track='git branch --set-upstream $(current_branch) origin/$(current_branch) && git fetch'
  62. # useful omz git plugin ones include:
  63. # ga, gc, gco, gb, gba, gm, grhh, ggpull, ggpush
  64. #
  65. # ggpull translates into `git pull origin <current branch>`, same for ggpush
  66. #
  67. # Note: both the gg's are extremely convenient! And safe, because you never know
  68. # if tracking has been setup properly on a branch.