Skip to content

Instantly share code, notes, and snippets.

@deeperton
Created March 6, 2026 18:30
Show Gist options
  • Select an option

  • Save deeperton/8b086dae79b4736ab54b31ac97d8489f to your computer and use it in GitHub Desktop.

Select an option

Save deeperton/8b086dae79b4736ab54b31ac97d8489f to your computer and use it in GitHub Desktop.
GIT aliases
# -------------------------------
# 5. GIT ENVIRONMENT CONFIG
# -------------------------------
export GIT_PS1_SHOWDIRTYSTATE=1
alias gst='git status'
alias gco='git checkout'
alias gci='git commit'
alias grb='git rebase'
alias gbr='git branch'
alias gad='git add -A'
alias gpl='git pull'
alias gpu='git push'
alias gfe='git fetch'
alias glg='git log --date-order --all --graph --format="%C(green)%h%Creset %C(yellow)%an%Creset %C(blue bold)%ar%Creset %C(red bold)%d%Creset%s"'
alias glg2='git log --date-order --all --graph --name-status --format="%C(green)%H%Creset %C(yellow)%an%Creset %C(blue bold)%ar%Creset %C(red bold)%d%Creset%s"'
alias glgs='git log --oneline --graph'
alias amend='git commit --amend -a --no-edit'
git_remove_remote_branch() {
git push origin --delete $1
}
git_merge_master() {
git checkout master
git pull
git checkout -
git merge master
}
git_rebase_master() {
git checkout master
git pull
git checkout -
git rebase master -i
}
git_temporary_switch_up() {
export TMP_BRANCH="$(parse_git_branch)"
git stash save
git fetch
git checkout $1
}
git_temporary_switch_back() {
git checkout $TMP_BRANCH
git stash pop
export TMP_BRANCH=""
}
git_checkout_guard() {
if [[ "$1" == "." || "$1" == ".." || "$1" == "../"* || "$1" == "./"* ]]; then
echo "Checkout Guard: looks like a path. Use: cd ... OR git restore <path> OR git switch <branch>"
return 2
fi
git switch "$@"
}
alias gch=git_checkout_guard
alias gitrm=git_remove_remote_branch
alias grep_all="git branch -a | tr -d \* | sed '/->/d' | xargs git grep"
alias gitmerge=git_merge_master
alias gitrebase=git_rebase_master
alias gitup=git_temporary_switch_up
alias gitback=git_temporary_switch_back
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment