dotfiles/git/.config/sh/alias.d/git.sh
Marty Oehme 78e678fe1f
git: Add main branch methods, Fix pushall
Fixed 'pushall' option xargs error.

Added dealing with 'main' branch instead of 'master' branch in checkout
and rebase aliases, so that when invoking the commands it will default
to a master branch and fall back to a main branch before complaining
that no corresponding branch exists.

Should (silently) fix git repositories which switched to main in the
last few months, and simultaneously allows me to switch this repository
to main branch (already done.)
2021-03-14 13:02:47 +01:00

77 lines
1.7 KiB
Bash

#!/usr/bin/env sh
if ! exist git; then
return 1
fi
# git alias
alias g='git'
alias ga='git add'
alias gaa='git add --all'
alias gai='git add -i'
alias gb='git branch'
alias gbd='git branch -d'
alias gc='git commit -v'
alias gc!='git commit -v --amend'
alias gcn!='git commit -v --no-edit --amend'
alias gcm='git checkout master 2>/dev/null || git checkout main'
alias gcd='git checkout develop'
alias gcb='git checkout -b'
alias gco='git checkout'
alias gd='git diff'
alias gds='git diff --staged'
alias gi='git ignore'
# show last committed content
alias gll='git last'
# show quick log overview
alias glg='git log --oneline --decorate --graph'
alias glga='git log --oneline --decorate --graph --remotes --all'
# show detailed log overview
alias glog='git log --stat'
# show detailed log overview with contents
alias gloog='git log --stat -p'
alias gf='git fetch'
alias gl='git pull'
alias gpn='git push --dry-run'
alias gp='git push'
alias gpf!='git push --force'
alias gpm='git pushmerge'
alias gpa='git pushall'
alias grv='git remote -v'
alias grs='git restore --staged'
alias grs!='git restore'
alias grb='git rebase'
alias grbi='git rebase -i'
alias grbc='git rebase --continue'
alias grbm='git rebase master || git rebase main'
alias gst='git status'
# if git is at least version 2.13, we can use git stash push
# in shells other than zsh, simply fall back to save
case "$(ps -cp "$$" -o command="")" in
*zsh*)
autoload -Uz is-at-least
if is-at-least 2.13 "$(git --version 2>/dev/null | awk '{print $3}')"; then
alias gsta='git stash push'
else
alias gsta='git stash save'
fi
;;
*) alias gsta='git stash save' ;;
esac
alias gstp='git stash pop'
alias gstl='git stash list'
alias gstL='git stash list --stat'