git.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. GIT_VER=$(git --version 2>/dev/null)
  29. GIT_VER=${GIT_VER:12:5}
  30. [[ $(version-compare $GIT_VER "1.8.3") -ge 0 ]] && DECO_COLOUR='%C(auto)' || DECO_COLOUR='%Cgreen'
  31. GL_PRETTY="'format:%C(yellow)%h %Creset%ad %Cblue%an:$DECO_COLOUR%d %Creset%s'"
  32. GL_OPTS="--graph --date=short --pretty=$GL_PRETTY"
  33. alias gl="git log $GL_OPTS"
  34. alias gla='gl --all' # show all refs, not only those reachable from current branch.
  35. alias glb='gl --simplify-by-decoration' # show mostly branches and tags.
  36. alias glh="git --no-pager log --max-count=15 $GL_OPTS" # show first few (head)
  37. alias glp='git log --graph --decorate -p'
  38. alias gls='git log --graph --decorate --stat'
  39. # Searching history.
  40. alias glG='git log --stat -G' # Search DIFFS - changes with given text.
  41. alias glS='git log --stat -S' # Search DIFFS - changes in number of given text.
  42. alias glg='git log --grep' # Search MESSAGES.
  43. # Submodule management.
  44. alias gsm='git submodule'
  45. alias gsmpull='git submodule foreach git pull origin master'
  46. alias gsmup='git submodule sync && git submodule update --init --recursive'
  47. # Fix tracking for origin if not there.
  48. alias track='git branch --set-upstream-to origin/$(__gitp_branch) && git fetch'
  49. # Autosquashing for simple fixups.
  50. alias grb='git rebase'
  51. alias grba='git rebase --abort'
  52. alias grbc='git rebase --continue'
  53. alias grbi='git rebase -i --autosquash'
  54. alias gcf='git commit --fixup'
  55. alias gcs='git commit --squash'
  56. # Create Work-In-Progress commits.
  57. alias gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1'
  58. alias gwip='git add -A; git rm $(git ls-files --deleted) 2>/dev/null; git commit -m "--wip--"'