Skip to content

Instantly share code, notes, and snippets.

@andrewdieken
Last active June 15, 2023 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewdieken/8e9d9406bed068b8307843561b2d11bf to your computer and use it in GitHub Desktop.
Save andrewdieken/8e9d9406bed068b8307843561b2d11bf to your computer and use it in GitHub Desktop.
Git Aliases
#!/bin/bash
## basic commands
alias gst="git status"
alias gbr="git branch"
alias gdf="git diff"
alias gco="git checkout"
alias gcob="git checkout -b"
alias gcm="git commit -m"
alias gfa='git fetch --all'
alias gsu="git submodule update"
## add file(s)
alias ga="git add"
alias gaa="git add ."
## master branch commands
alias gplm="git pull origin master"
alias gcom="git checkout master"
alias gmm="git merge master"
alias grm="git reset --hard origin/master"
## current branch commands
alias gcb="git rev-parse --abbrev-ref HEAD"
alias gpl='git pull origin "$(gcb)"'
alias gpsh='git push origin "$(gcb)"'
## delete branch
alias gbrd="git branch -D"
# pretty print n number of logs
alias glp='git log --pretty=format:"%h - %an, %ar : %s" | tail -n $1'
## clear all current unstaged changes
function gcla () {
git add .
git stash
git stash clear
}
## first modified file commands
## NOTE: this only works if your status output follows the following format:
## modified: <modified_file_name>
function gff () {
gst | grep modified | head -n 1 | cut -d ':' -f '2' | xargs
}
alias gdff='gdf "$(gff)"'
alias gaff='ga "$(gff)"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment