Skip to content

Instantly share code, notes, and snippets.

@serguk89
Created December 24, 2020 22:19
Show Gist options
  • Save serguk89/54b1cb873eabb530f5b943bcee17b131 to your computer and use it in GitHub Desktop.
Save serguk89/54b1cb873eabb530f5b943bcee17b131 to your computer and use it in GitHub Desktop.
Aliases for Git
#---------------------------------------------------------------------------------------
# Aliases for Git
#---------------------------------------------------------------------------------------
alias gc="git clone"
alias gcm="git commit -m"
alias gco="git checkout"
alias grv='git remote -v'
alias gba="git branch -a"
alias gwait="git reset HEAD"
alias gundo="git reset --soft HEAD^"
alias grs="git clean -f && git reset --hard HEAD" # Removes all changes, even untracked files
alias gpr='git reset --hard HEAD && git pull'
alias gl="git log --graph --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
alias glb='git log --oneline --decorate --graph --all'
alias gitstat='git status'
alias gpl="git pull --rebase"
alias gpsf="git push --force-with-lease"
alias grb="git rebase"
alias grbi='git rebase -i'
alias grba='git rebase --abort'
alias grbc='git rebase --continue'
# Remove local branches that have already been merged in the remote repository
alias gcmb="git branch --merged | grep -Ev '(^\*|master)' | xargs git branch -d"
# Sets the upstream branch to be the same branch as the locally named branch
alias gset='git branch --set-upstream-to=origin/`git symbolic-ref --short HEAD`'
# Do an interactive rebase back N number of commits (e.g. grn 3)
grn() { git rebase -i HEAD~"$1"; }
# Do an interactive rebase to a supplied commit hash (e.g. grbc 80e1625)
grbic() { git rebase -i "$1"; }
# Pull / sync with original upstrean
alias gpu='git fetch upstream && git checkout master && git rebase upstream/master'
alias gpo="git push origin"
alias gm="git merge"
alias glog="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment