/ git

Git aliases and load it through a file in to terminal

Git Aliases and set it up in UNIX

I have created a list of git aliases that can be used in our day to day work. Most of us might have configured this. But I have listed few more aliases that are normally not used. like 'ggr'

# Add and Removes
alias "ga"='git add'
alias "gai"='git add -i'
alias 'grm'='git rm'
alias 'gra'='git remote add'
alias "grr"='git remote rm'

# Commit and Pushes
alias "gcm"='git commit -m'
alias "gca"='git commit -am'
alias "gp"='git push'
alias "gpu"='git pull'
alias "gpo"='git push origin'
alias "gri"='git rebase -i'

# Logs
alias "gl"='git log'
alias "gll"='git log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat'
alias "glnc"='git log --pretty=format:"%h\\ %s\\ [%cn]"'
alias "ggr"='git log --graph --oneline --decorate --all'

# Status and Diffs
alias "gs"='git status'
alias "gd"='git diff'
alias "gdc"='git diff --cached'

# Clone and Fetch
alias "gcl"='git clone'
alias "gf"='git fetch'

# Branches
alias "gb"='git branch'
alias "gc"='git checkout'
alias "gcn"='git checkout -b'

# Git Resets
alias "gr"="git reset"
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 Stashes
alias "gst"="git stash"
alias "gsl"="git stash list"
alias "gsa"="git stash apply"
alias "gss"="git stash save"

One issue that I faced with my machine is that I was not able to load this when I do 'su',

Finally I figured it how to do.

The steps are really simple.

  1. Save this aliases in a file, let's say 'my_git_aliases.txt'

  2. Open vim ~/.bash_profile

  3. add to the end of file "source PathTo/my_git_aliases.txt" ( This will load the aliases in terminal that will be opened)

  4. add it to the end of file "export ENV=PathTo/my_git_aliases.txt" ( This will make sure that when we do a "su" it loads the aliases to 'su' terminal)

  5. Last but best option: If you want the git aliases to be available for all user.
    Then, open 'vim /etc/profile' and add the "source PathTo/my_git_aliases.txt" to the end of file.

Hope it helps everyone. :)