Skip to content

Instantly share code, notes, and snippets.

@gunjanpatel
Last active May 8, 2018 07:23
Show Gist options
  • Select an option

  • Save gunjanpatel/97f254fef0430dc7e7f6a53b123197e6 to your computer and use it in GitHub Desktop.

Select an option

Save gunjanpatel/97f254fef0430dc7e7f6a53b123197e6 to your computer and use it in GitHub Desktop.
Setup Git short codes and terminal them to show branch and path

Git short commands

You can enable short commands by updating your home .gitconfig file. Goto /home/{user}/.gitconfig file and add contents from https://gist.github.com/gunjanpatel/10019184 file.

Beautify terminal for git commands

1. Create the files which you will need to copy later from git repository

touch ~/.git-completion.bash
touch ~/.git-prompt.sh

2. Update Completion file

Copy source from git-completion.bash file and paste it into your newly created file. Location of file:

gedit ~/.git-completion.bash

or

/home/{user}/.git-completion.bash

Update permission if required

chmod 755 ~/.git-completion.bash

3. Update Prompt file

Copy source from git-prompt.sh file and paste it into your newly created file. Location of file:

gedit ~/.git-prompt.sh

or

/home/{user}/.git-prompt.sh

Update permission if required

chmod 755 ~/.git-prompt.sh

4. Update .bashrc file

Be careful while doing below steps

Find force_color_prompt in your file and remove comment #.

Before

#force_color_prompt=yes

After

force_color_prompt=yes

Copy following code in the end of the .bashrc file.

source ~/.git-completion.bash
source ~/.git-prompt.sh

MAGENTA="\[\033[0;35m\]"
YELLOW="\[\033[0;33m\]"
BLUE="\[\033[34m\]"
LIGHT_GRAY="\[\033[0;37m\]"
CYAN="\[\033[0;36m\]"
GREEN="\[\033[0;32m\]"
GIT_PS1_SHOWDIRTYSTATE=true
export LS_OPTIONS='--color=auto'
export CLICOLOR='Yes'
export LSCOLORS=gxfxbEaEBxxEhEhBaDaCaD

export PS1=$LIGHT_GRAY"\u@\h"'$(
    if [[ $(__git_ps1) =~ \*\)$ ]]
    # a file has been modified but not added
    then echo "'$YELLOW'"$(__git_ps1 " (%s)")
    elif [[ $(__git_ps1) =~ \+\)$ ]]
    # a file has been added, but not commited
    then echo "'$MAGENTA'"$(__git_ps1 " (%s)")
    # the state is clean, changes are commited
    else echo "'$CYAN'"$(__git_ps1 " (%s)")
    fi)'$BLUE" \w"$GREEN": "

alias ll='ls -lah'
alias gg='git status -s'

Thanks

Enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment