Git Autocomplete & Branches
If you work with Git’s source code control tool, and you’d like to work more like a pro, try this out…
Clone the git repository (https://github.com/git/git) to a folder in your home directory called ‘dev‘. You’ll get two scripts that can be added to your .bash_profile/.bashrc that will enable autocomplete for the commands/branch names, AND you’ll also get a script that can be added to your command line so that if you’re working on the command line in a directory that has a corresponding git repository, it will let you know the status of the branch your working on (ahead/out of sync/behind) and the name of the branch you’re on… Something like:
My CLI shows: [user]@[machineID] [pwd] ([branch_name]):
# Set git autocompletion and PS1 integration if [ -f ~/dev/git/contrib/completion/git-completion.bash ]; then . ~/dev/git/contrib/completion/git-completion.bash fi if [ -f ~/dev/git/contrib/completion/git-prompt.sh ]; then . ~/dev/git/contrib/completion/git-prompt.sh fi if [ -f ~dev/git/contrib/completion/bash_completion ]; then . ~dev/git/contrib/completion/bash_completion fi 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 $GREEN\w"'$( 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)'"$GREEN: "
Enjoy your ever so slightly more intelligent command prompt for git!
Tab – autocompletes on the command line for git commands and git branch names
Better command line information for git directories checked out locally.