|
| 1 | +# shellcheck shell=bash |
| 2 | +cite 'about-alias' |
| 3 | +about-alias 'git aliases from oh-my-zsh' |
| 4 | + |
| 5 | +# We are not vendoring this, as we need to adapt it to bash :( |
| 6 | + |
| 7 | +# MIT License |
| 8 | + |
| 9 | +# Copyright (c) 2009-2021 Robby Russell and contributors (https://github.com/ohmyzsh/ohmyzsh/contributors) |
| 10 | + |
| 11 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | +# of this software and associated documentation files (the "Software"), to deal |
| 13 | +# in the Software without restriction, including without limitation the rights |
| 14 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | +# copies of the Software, and to permit persons to whom the Software is |
| 16 | +# furnished to do so, subject to the following conditions: |
| 17 | + |
| 18 | +# The above copyright notice and this permission notice shall be included in all |
| 19 | +# copies or substantial portions of the Software. |
| 20 | + |
| 21 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 27 | +# SOFTWARE. |
| 28 | + |
| 29 | +# Load after regular git aliases |
| 30 | +# BASH_IT_LOAD_PRIORITY: 160 |
| 31 | + |
| 32 | +# |
| 33 | +# Functions |
| 34 | +# |
| 35 | + |
| 36 | +# The name of the current branch |
| 37 | +function git_current_branch() { |
| 38 | + _git-branch |
| 39 | +} |
| 40 | + |
| 41 | +# Pretty log messages |
| 42 | +function _git_log_prettily() { |
| 43 | + if [ -n "$1" ]; then |
| 44 | + git log --pretty="$1" |
| 45 | + fi |
| 46 | +} |
| 47 | + |
| 48 | +# Warn if the current branch is a WIP |
| 49 | +function work_in_progress() { |
| 50 | + exists=$(git log -n 1 2> /dev/null | grep -q -c "\-\-wip\-\-") |
| 51 | + if $exists; then |
| 52 | + echo "WIP!!" |
| 53 | + fi |
| 54 | +} |
| 55 | + |
| 56 | +# Check if main exists and use instead of master |
| 57 | +function git_main_branch() { |
| 58 | + command git rev-parse --git-dir &> /dev/null || return |
| 59 | + local branch |
| 60 | + for branch in main trunk; do |
| 61 | + if command git show-ref -q --verify refs/heads/$branch; then |
| 62 | + echo $branch |
| 63 | + return |
| 64 | + fi |
| 65 | + done |
| 66 | + echo master |
| 67 | +} |
| 68 | + |
| 69 | +# |
| 70 | +# Aliases |
| 71 | +# (sorted alphabetically) |
| 72 | +# |
| 73 | + |
| 74 | +alias g='git' |
| 75 | + |
| 76 | +alias ga='git add' |
| 77 | +alias gaa='git add --all' |
| 78 | +alias gapa='git add --patch' |
| 79 | +alias gau='git add --update' |
| 80 | +alias gav='git add --verbose' |
| 81 | +alias gap='git apply' |
| 82 | +alias gapt='git apply --3way' |
| 83 | + |
| 84 | +alias gb='git branch' |
| 85 | +alias gba='git branch -a' |
| 86 | +alias gbd='git branch -d' |
| 87 | +alias gbda='git branch --no-color --merged | command grep -vE "^(\+|\*|\s*($(git_main_branch)|development|develop|devel|dev)\s*$)" | command xargs -n 1 git branch -d' |
| 88 | +alias gbD='git branch -D' |
| 89 | +alias gbl='git blame -b -w' |
| 90 | +alias gbnm='git branch --no-merged' |
| 91 | +alias gbr='git branch --remote' |
| 92 | +alias gbs='git bisect' |
| 93 | +alias gbsb='git bisect bad' |
| 94 | +alias gbsg='git bisect good' |
| 95 | +alias gbsr='git bisect reset' |
| 96 | +alias gbss='git bisect start' |
| 97 | + |
| 98 | +alias gc='git commit -v' |
| 99 | +alias gc!='git commit -v --amend' |
| 100 | +alias gcn!='git commit -v --no-edit --amend' |
| 101 | +alias gca='git commit -v -a' |
| 102 | +alias gca!='git commit -v -a --amend' |
| 103 | +alias gcan!='git commit -v -a --no-edit --amend' |
| 104 | +alias gcans!='git commit -v -a -s --no-edit --amend' |
| 105 | +alias gcam='git commit -a -m' |
| 106 | +alias gcsm='git commit -s -m' |
| 107 | +alias gcb='git checkout -b' |
| 108 | +alias gcf='git config --list' |
| 109 | +alias gcl='git clone --recurse-submodules' |
| 110 | +alias gclean='git clean -id' |
| 111 | +alias gpristine='git reset --hard && git clean -dffx' |
| 112 | +alias gcm='git checkout $(git_main_branch)' |
| 113 | +alias gcd='git checkout develop' |
| 114 | +alias gcmsg='git commit -m' |
| 115 | +alias gco='git checkout' |
| 116 | +alias gcount='git shortlog -sn' |
| 117 | +alias gcp='git cherry-pick' |
| 118 | +alias gcpa='git cherry-pick --abort' |
| 119 | +alias gcpc='git cherry-pick --continue' |
| 120 | +alias gcs='git commit -S' |
| 121 | + |
| 122 | +alias gd='git diff' |
| 123 | +alias gdca='git diff --cached' |
| 124 | +alias gdcw='git diff --cached --word-diff' |
| 125 | +alias gdct='git describe --tags $(git rev-list --tags --max-count=1)' |
| 126 | +alias gds='git diff --staged' |
| 127 | +alias gdt='git diff-tree --no-commit-id --name-only -r' |
| 128 | +alias gdw='git diff --word-diff' |
| 129 | + |
| 130 | +function gdnolock() { |
| 131 | + git diff "$@" ":(exclude)package-lock.json" ":(exclude)*.lock" |
| 132 | +} |
| 133 | + |
| 134 | +alias gf='git fetch' |
| 135 | +# --jobs=<n> was added in git 2.8 |
| 136 | +alias gfa='git fetch --all --prune --jobs=10' |
| 137 | +alias gfo='git fetch origin' |
| 138 | + |
| 139 | +alias gfg='git ls-files | grep' |
| 140 | + |
| 141 | +alias gg='git gui citool' |
| 142 | +alias gga='git gui citool --amend' |
| 143 | + |
| 144 | +function ggf() { |
| 145 | + [[ "$#" != 1 ]] && local b="$(git_current_branch)" |
| 146 | + git push --force origin "${b:=$1}" |
| 147 | +} |
| 148 | +function ggfl() { |
| 149 | + [[ "$#" != 1 ]] && local b="$(git_current_branch)" |
| 150 | + git push --force-with-lease origin "${b:=$1}" |
| 151 | +} |
| 152 | + |
| 153 | +function ggl() { |
| 154 | + if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then |
| 155 | + git pull origin "${*}" |
| 156 | + else |
| 157 | + [[ "$#" == 0 ]] && local b="$(git_current_branch)" |
| 158 | + git pull origin "${b:=$1}" |
| 159 | + fi |
| 160 | +} |
| 161 | + |
| 162 | +function ggp() { |
| 163 | + if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then |
| 164 | + git push origin "${*}" |
| 165 | + else |
| 166 | + [[ "$#" == 0 ]] && local b="$(git_current_branch)" |
| 167 | + git push origin "${b:=$1}" |
| 168 | + fi |
| 169 | +} |
| 170 | + |
| 171 | +function ggpnp() { |
| 172 | + if [[ "$#" == 0 ]]; then |
| 173 | + ggl && ggp |
| 174 | + else |
| 175 | + ggl "${*}" && ggp "${*}" |
| 176 | + fi |
| 177 | +} |
| 178 | + |
| 179 | +function ggu() { |
| 180 | + [[ "$#" != 1 ]] && local b="$(git_current_branch)" |
| 181 | + git pull --rebase origin "${b:=$1}" |
| 182 | +} |
| 183 | + |
| 184 | +alias ggpur='ggu' |
| 185 | +alias ggpull='git pull origin "$(git_current_branch)"' |
| 186 | +alias ggpush='git push origin "$(git_current_branch)"' |
| 187 | + |
| 188 | +alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)' |
| 189 | +alias gpsup='git push --set-upstream origin $(git_current_branch)' |
| 190 | + |
| 191 | +alias ghh='git help' |
| 192 | + |
| 193 | +alias gignore='git update-index --assume-unchanged' |
| 194 | +alias gignored='git ls-files -v | grep "^[[:lower:]]"' |
| 195 | +alias git-svn-dcommit-push='git svn dcommit && git push github $(git_main_branch):svntrunk' |
| 196 | + |
| 197 | +alias gk='\gitk --all --branches' |
| 198 | +alias gke='\gitk --all $(git log -g --pretty=%h)' |
| 199 | + |
| 200 | +alias gl='git pull' |
| 201 | +alias glg='git log --stat' |
| 202 | +alias glgp='git log --stat -p' |
| 203 | +alias glgg='git log --graph' |
| 204 | +alias glgga='git log --graph --decorate --all' |
| 205 | +alias glgm='git log --graph --max-count=10' |
| 206 | +alias glo='git log --oneline --decorate' |
| 207 | +alias glol="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'" |
| 208 | +alias glols="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --stat" |
| 209 | +alias glod="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset'" |
| 210 | +alias glods="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short" |
| 211 | +alias glola="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --all" |
| 212 | +alias glog='git log --oneline --decorate --graph' |
| 213 | +alias gloga='git log --oneline --decorate --graph --all' |
| 214 | +alias glp="_git_log_prettily" |
| 215 | + |
| 216 | +alias gm='git merge' |
| 217 | +alias gmom='git merge origin/$(git_main_branch)' |
| 218 | +alias gmt='git mergetool --no-prompt' |
| 219 | +alias gmtvim='git mergetool --no-prompt --tool=vimdiff' |
| 220 | +alias gmum='git merge upstream/$(git_main_branch)' |
| 221 | +alias gma='git merge --abort' |
| 222 | + |
| 223 | +alias gp='git push' |
| 224 | +alias gpd='git push --dry-run' |
| 225 | +alias gpf='git push --force-with-lease' |
| 226 | +alias gpf!='git push --force' |
| 227 | +alias gpoat='git push origin --all && git push origin --tags' |
| 228 | +alias gpu='git push upstream' |
| 229 | +alias gpv='git push -v' |
| 230 | + |
| 231 | +alias gr='git remote' |
| 232 | +alias gra='git remote add' |
| 233 | +alias grb='git rebase' |
| 234 | +alias grba='git rebase --abort' |
| 235 | +alias grbc='git rebase --continue' |
| 236 | +alias grbd='git rebase develop' |
| 237 | +alias grbi='git rebase -i' |
| 238 | +alias grbm='git rebase $(git_main_branch)' |
| 239 | +alias grbs='git rebase --skip' |
| 240 | +alias grev='git revert' |
| 241 | +alias grh='git reset' |
| 242 | +alias grhh='git reset --hard' |
| 243 | +alias groh='git reset origin/$(git_current_branch) --hard' |
| 244 | +alias grm='git rm' |
| 245 | +alias grmc='git rm --cached' |
| 246 | +alias grmv='git remote rename' |
| 247 | +alias grrm='git remote remove' |
| 248 | +alias grs='git restore' |
| 249 | +alias grset='git remote set-url' |
| 250 | +alias grss='git restore --source' |
| 251 | +alias grst='git restore --staged' |
| 252 | +alias grt='cd "$(git rev-parse --show-toplevel || echo .)"' |
| 253 | +alias gru='git reset --' |
| 254 | +alias grup='git remote update' |
| 255 | +alias grv='git remote -v' |
| 256 | + |
| 257 | +alias gsb='git status -sb' |
| 258 | +alias gsd='git svn dcommit' |
| 259 | +alias gsh='git show' |
| 260 | +alias gsi='git submodule init' |
| 261 | +alias gsps='git show --pretty=short --show-signature' |
| 262 | +alias gsr='git svn rebase' |
| 263 | +alias gss='git status -s' |
| 264 | +alias gst='git status' |
| 265 | + |
| 266 | +# use the default stash push on git 2.13 and newer |
| 267 | +alias gsta='git stash push' |
| 268 | + |
| 269 | +alias gstaa='git stash apply' |
| 270 | +alias gstc='git stash clear' |
| 271 | +alias gstd='git stash drop' |
| 272 | +alias gstl='git stash list' |
| 273 | +alias gstp='git stash pop' |
| 274 | +alias gsts='git stash show --text' |
| 275 | +alias gstu='git stash --include-untracked' |
| 276 | +alias gstall='git stash --all' |
| 277 | +alias gsu='git submodule update' |
| 278 | +alias gsw='git switch' |
| 279 | +alias gswc='git switch -c' |
| 280 | + |
| 281 | +alias gts='git tag -s' |
| 282 | +alias gtv='git tag | sort -V' |
| 283 | +function gtl() { |
| 284 | + git tag --sort=-v:refname -n -l "${1}*" |
| 285 | +} |
| 286 | + |
| 287 | +alias gunignore='git update-index --no-assume-unchanged' |
| 288 | +alias gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1' |
| 289 | +alias gup='git pull --rebase' |
| 290 | +alias gupv='git pull --rebase -v' |
| 291 | +alias gupa='git pull --rebase --autostash' |
| 292 | +alias gupav='git pull --rebase --autostash -v' |
| 293 | +alias glum='git pull upstream $(git_main_branch)' |
| 294 | + |
| 295 | +alias gwch='git whatchanged -p --abbrev-commit --pretty=medium' |
| 296 | +alias gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign -m "--wip-- [skip ci]"' |
| 297 | + |
| 298 | +alias gam='git am' |
| 299 | +alias gamc='git am --continue' |
| 300 | +alias gams='git am --skip' |
| 301 | +alias gama='git am --abort' |
| 302 | +alias gamscp='git am --show-current-patch' |
| 303 | + |
| 304 | +function grename() { |
| 305 | + if [[ -z "$1" || -z "$2" ]]; then |
| 306 | + echo "Usage: $0 old_branch new_branch" |
| 307 | + return 1 |
| 308 | + fi |
| 309 | + |
| 310 | + # Rename branch locally |
| 311 | + git branch -m "$1" "$2" |
| 312 | + # Rename branch in origin remote |
| 313 | + if git push origin :"$1"; then |
| 314 | + git push --set-upstream origin "$2" |
| 315 | + fi |
| 316 | +} |
0 commit comments