Skip to content

Instantly share code, notes, and snippets.

@tandv592082
Created November 17, 2022 03:19
Show Gist options
  • Select an option

  • Save tandv592082/bf97f08d348d64928fe78a5a93240aa7 to your computer and use it in GitHub Desktop.

Select an option

Save tandv592082/bf97f08d348d64928fe78a5a93240aa7 to your computer and use it in GitHub Desktop.
Git alias command
#############GIT ALIAS COMMAND###################
#Basic
alias gst='git status -s'
alias gcl='git clone'
alias gci='git commit'
alias gco='git checkout'
alias gbr='git branch'
alias gr='git reset'
alias gcp='git cherry-pick'
alias ggr='git grep -Ii'
#Tweak defaults
alias gdiff='git diff --word-diff'
alias gbranch='git branch -ra'
alias ggrep='git grep -Ii'
alias gbra='git branch -ra'
alias gai='git add --interactive'
# grep on filename
alias gf='git "!git ls-files | grep -i"'
# commit
alias gcm='git commit -m'
alias gcma='git commit -a -m'
alias gca='git commit --amend'
alias gamend='git commit --amend'
alias gcaa='git commit -a --amend -C HEAD'
# log commands
alias gls='git log --pretty=format:"%C(green)%h\\ %C(yellow)[%ad]%Cred%d\\ %Creset%s%Cblue\\ [%an]" --decorate --date=relative'
alias gll='git log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [a:%an,c:%cn]" --decorate --numstat'
alias glnc='git log --pretty=format:"%h\\ %s\\ [%cn]"'
alias gfl='git log -u'
alias gfilelog='git log -u'
# diff
alias gd='git diff --word-diff'
alias gdc='git diff --cached'
# diff last commit
alias gdlc='git diff --cached HEAD^'
# reset commands
alias gr1='git reset HEAD^'
alias gr2='git reset HEAD^^'
alias grh='git reset --hard'
alias grh1='git reset HEAD^ --hard'
alias grh2='git reset HEAD^^ --hard'
# git svn
alias gsvnr='git svn rebase'
alias gsvnd='git svn dcommit'
alias gsvnl='git svn log --oneline --show-commit'
# stash
alias gsl='git stash list'
alias gsa='git stash apply'
alias gss='git stash save'
# assume aliases
alias gassume='git update-index --assume-unchanged'
alias gunassume='git update-index --no-assume-unchanged'
# show assumed files
alias gassumed='git "!git ls-files -v | grep ^h | cut -c 3-"'
# unassume all the assumed files
alias gunassumeall='git "!git assumed | xargs git update-index --no-assume-unchanged"'
# subtree
# add
alias gsba='git "!f() { git subtree add --prefix $2 $1 master --squash; }; f"'
# update/pull
alias gsbu='git "!f() { git subtree pull --prefix $2 $1 master --squash; }; f"'
# various useful
# last tag created
alias glasttag='git describe --tags --abbrev=0'
alias glt='git describe --tags --abbrev=0'
# conflict/merges
alias gours='git "!f() { git co --ours $@ && git add $@; }; f"'
alias gtheirs='git "!f() { git co --theirs $@ && git add $@; }; f"'
#list remotes
alias grem="!git config -l | grep remote.*url | tail -n +2"
#apply patch from other local repo
alias glap='git "!f() { git --git-dir=$1 format-patch -k -1 --stdout $2 | git am -3 -k; }; f"'
#open markdown files edited in last commit
alias glast='git "!gvim $(git show HEAD --format="" --name-only | grep -e .*md$ | xargs)"'
#open just created markdown in working directory
# initial empty commit
alias gempty='git "!git commit -am\"[empty] Initial commit\" --allow-empty"'
# list all aliases
alias gla='git "!git config -l | grep alias | cut -c 7-"'
# convoluted aliases
# grep from root folder
alias ggra='git "!f() { A=$(pwd) && TOPLEVEL=$(git rev-parse --show-toplevel) && cd $TOPLEVEL && git grep --full-name -In $1 | xargs -I{} echo $TOPLEVEL/{} && cd $A; }; f"'
#rename branch tree to done-
alias gdone='git "!f() { git branch | grep "$1" | cut -c 3- | grep -v done | xargs -I{} git branch -m {} done-{}; }; f"'
#add bitbucket remote
alias gra='git "!f() { git remote add $1 https://bitbucket.org/$2.git; }; f"'
# worktree list
alias gwl='git worktree list'
# undo from here http://megakemp.com/2016/08/25/git-undo/
alias gundo='git "!f() { git reset --hard $(git rev-parse --abbrev-ref HEAD)@{${1-1}}; }; f"'
@tandv592082
Copy link
Author

To install, copy and paste to ~.bashrc, then reset terminal.

source ~/.bashrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment