Skip to content

Instantly share code, notes, and snippets.

@matzar
Last active October 23, 2024 07:42
Show Gist options
  • Save matzar/3a8e8b4d28429d62420689a894583247 to your computer and use it in GitHub Desktop.
Save matzar/3a8e8b4d28429d62420689a894583247 to your computer and use it in GitHub Desktop.
git bash aliases and functions to improve your workflow.
# Copy and paste the contents of this file to your .zshrc or .bash_profile file.
#
# Example use:
# to commit with only one letter go:
#
# c feat: your commit message
#
# In the above example, the following would happen:
# - Your changes would be staged for commit
# - A commit with a message - "feat: your commit message" - would be created.
#
# There is no need for wrapping your commit messages in double-quotation marks but if you want to use parenthesis ()
# it is best to actually wrap your commit message in double-quotation marks, eg.:
# c "feat(new): new features description"
# ----------------------
# Git Aliases
# ----------------------
# add
alias a='git add'
alias aa='git add --all'
alias au='git add --update'
# branch
alias b='git checkout -b'
alias bb='git branch --all'
alias vv='git branch -vv'
alias bd='git branch -d'
alias su='git branch --set-upstream-to' # git branch --set-upstream-to origin/master
alias pp='git checkout -p'
# clone
alias cl='git clone'
# commit
alias am='git commit --amend'
alias cf='git commit --fixup'
# stage changes and ammend commit
function aam() { aa; am; }
# checkout
alias ch='git checkout'
alias m='git checkout -'
alias chm='git checkout master'
alias chs='git checkout staging'
alias chd='git checkout develop'
alias dis='git checkout --' # discard file name
alias discard='git checkout --' # discard file name
# diff
alias d='git diff'
alias dh='git diff HEAD'
alias dw='git diff --word-diff'
# show
alias sh='git show'
# init
alias ii='git init'
#
alias k='git-gui&'
alias f='gitk --follow'
alias kf='gitk --follow'
# check if the path is in .gitignore
alias gc='git check-ignore -v'
# merge
alias mm='git merge --no-ff'
alias ma='git merge --abort'
alias mc='git merge --continue'
# pull
alias pl='git pull origin'
alias plm='git pull origin && npm i'
alias pla='git pull --all'
alias plr='git pull --rebase'
# push
alias p='git push'
alias pom='git push origin master'
alias pu='git push -u origin'
# alias puo='git push -u origin'
alias puom='git push -u origin master'
# rebase
alias grr='git rebase -i --root'
# reflog
alias ref='git reflog' # show deleted commits
alias reflog='git reflog'
# remote
alias v='git remote -v'
alias rs='git remote set-url origin'
# alias rr='git remote add origin'
# reset
alias res0='git reset --soft HEAD^' # reset current commit
alias res1='git reset --soft HEAD^1' # reset to the previous commit
alias mix='git reset --mixed HEAD^1'
# status
alias s='git status'
# alias ss='git status --short'
# stash
alias stl='git stash list'
alias std='git stash drop'
alias stc='git stash clear'
alias stp='git stash push' # - Save your local modifications to a new stash entry and roll them back to HEAD (in the working tree and in the index). The <message> part is optional and gives the description along with the stashed state.
# alias sts='git stash save' - Deprecated in favour of git stash push.
alias sta='git stash apply' # - Like pop, but do not remove the state from the stash list. Unlike pop, <stash> may be any commit that looks like a commit created by stash push or stash create.
# alias stp='git stash pop' - Remove a single stashed state from the stash list and apply it on top of the current working tree state, i.e., do the inverse operation of git stash push. The working directory must match the index.
function rs() {
# delete all stashes older than stash@{19}:
# while git stash drop 'stash@{20}'; do true; done
while git stash drop "$*"; do true; done
}
# submodule
alias subi='git submodule init'
alias subu='git submodule update'
alias sub='git submodule add'
# switch
alias sw="git switch"
# tag
function tag() { git tag -a "$1"; }
function tm() { git tag -a "$1" -m "$2"; }
# ----------------------
# full word git aliases
# ----------------------
alias graph='git log --graph --oneline --decorate --all'
alias log='git log --pretty=format:"%h %ad %s" --date=short --all'
alias logl='git log --all --grep="$1"'
alias show='git show'
# ----------------------
# bash aliases
# ----------------------
alias ab='atom ~/.bash_profile'
alias cb='code ~/.bash_profile'
#alias bpn='start notepad++ ~/.bash_profile'
alias sb='source ~/.bash_profile'
alias j='jekyll serve'
alias cv='cd ~/documents/matzar.github.io/assets/pdf'
alias edi="git config --global core.editor 'code --wait'"
alias pc="pwd|pbcopy"
alias copy="pwd|pbcopy"
# ----------------------
# Git Functions
# ----------------------
# Git log find by commit message
function cj() { git add --all; git commit -m "$*"; jekyll serve; }
#function glf() { git log --all --grep="$1"; }
function g() { git add --all; git commit -m "$*"; git push; }
# function g() { git add --all; git commit -m "$*"; git push; git push gitlab master; }
#function gm() { git add --all; git commit -m ":memo: $*"; git push; }
#function gw() { git add --all; git commit -m ":wrench: $*"; git push; }
# function c() { git commit -m "$*"; }
function c() { git add --all; git commit -S -m "$*"; }
# sign commit
function cs() { git add --all; git commit -S -m "$*"; }
function cc() { git commit -m "$*"; }
function cm() { git commit -m "$*"; }
function st() { git add --all; git stash; }
function ca() { git rm -r --cached .; }
# function r() { git reset --soft "$*"; git stash; }
function switch() {
git switch -c "$*" --track "$*";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment