blog and things oh hi there!
My top 10 Git Bash snippets
alias gs="git status"

This is my most used alias and I like to keep the alias short and easy to remember.

alias gupd='git checkout develop && git pull && git fetch --all'

I am often working on multiple branches and to make sure I am always up to date with the repository, I like to run this command from time to time.

alias grid="git rebase -i develop"

I like to squash all my commits before making a pull request and to rebase off of the develop branch, so this command is pretty handy.

alias gcdf="git clean -df"

A short command that will force delete unstaged files and directories.

alias gss="git stash save $1"

For when you need to jump from branch to branch and move code around. You can use it like this: gss name_to_remember.

alias gsp="git stash pop"

This one goes hand in hand with the above gss command to pop the latest stashed code.

alias gdf="git diff"

A basic alias to use the diff command. You can pass arguments to it like gdf --staged or gdf HEAD.

function gpof { git push origin +"$@";}

A shortcut to force push to the remote repository. This command takes in the remote branch name as it's argument like gpof feature_branch_name

function gcbn { command $(git symbolic-ref --short HEAD | pbcopy) && echo $(pbpaste);}

While going between the terminal and Github, I need a quick way to get the branch name and this alias will echo out the current branch name and also copy it to your clipboard. (OS X only since I am using pbcopy)

function gl {
    git log -n $1 --pretty=format:"%C(yellow)%h %C(blue)%ad%C(red)%d %C(reset)%s%C(green) [%cn]" --decorate --date=short;
}

A log function that will show you the latest x number of formatted commits.

© 2019 Kevin Jung