git.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Git Aliases (mostly mnemonic)
  2. alias ga.='git add -A .'
  3. alias ga='git add'
  4. alias gap='git add -p'
  5. alias gb='git branch'
  6. alias gba='git branch -a'
  7. alias gbav='git branch -av'
  8. alias gbd='git branch -D'
  9. alias gbv='git branch -v'
  10. alias gc='git commit -v'
  11. alias gco='git checkout'
  12. alias gcob='git checkout -b'
  13. alias gcop='git checkout -p'
  14. alias gcp='git cherry-pick'
  15. alias gd='git diff'
  16. alias gds='git diff --staged'
  17. alias gf='git fetch --all --tags && git fetch --all --prune'
  18. alias ggpush='git push -u origin $(__gitp_branch)'
  19. alias gm='git merge'
  20. alias gr='git reset'
  21. alias grh='git reset --hard'
  22. alias grhh='git reset HEAD --hard'
  23. alias grs='git reset --soft'
  24. alias grv='git remote -v'
  25. alias gs='git status'
  26. alias gsr='git show --format=raw' # all info about a commmit.
  27. # Git log (`gl`). Displays graph, decorations, users and dates.
  28. [[ $(version-compare $GIT_VER "1.8.3") -ge 0 ]] && DECO_COLOUR='%C(auto)' || DECO_COLOUR='%Cgreen'
  29. GL_PRETTY="'format:%C(yellow)%h %Creset%ad %Cblue%an:$DECO_COLOUR%d %Creset%s'"
  30. GL_OPTS="--graph --date=short --pretty=$GL_PRETTY"
  31. alias gl="git log $GL_OPTS"
  32. alias gla='gl --all' # show all refs, not only those reachable from current branch.
  33. alias glb='gl --simplify-by-decoration' # show mostly branches and tags.
  34. alias glh="git --no-pager log --max-count=15 $GL_OPTS" # show first few (head)
  35. alias glp='git log --graph --decorate -p'
  36. alias gls='git log --graph --decorate --stat'
  37. # Searching history.
  38. alias glG='git log --stat -G' # Search DIFFS - changes with given text.
  39. alias glS='git log --stat -S' # Search DIFFS - changes in number of given text.
  40. alias glg='git log --grep' # Search MESSAGES.
  41. # Submodule management.
  42. alias gsm='git submodule'
  43. alias gsmpull='git submodule foreach git pull origin master'
  44. alias gsmup='git submodule sync && git submodule update --init --recursive'
  45. # Fix tracking for origin if not there.
  46. alias track='git branch --set-upstream-to origin/$(__gitp_branch) && git fetch'
  47. # Autosquashing for simple fixups.
  48. alias grb='git rebase'
  49. alias grba='git rebase --abort'
  50. alias grbc='git rebase --continue'
  51. alias grbi='git rebase -i --autosquash'
  52. alias gcf='git commit --fixup'
  53. alias gcs='git commit --squash'
  54. # Create Work-In-Progress commits.
  55. alias gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1'
  56. alias gwip='git add -A; git rm $(git ls-files --deleted) 2>/dev/null; git commit -m "--wip--"'