Quantcast
Channel: blog.strug.de » bash
Viewing all articles
Browse latest Browse all 2

How To Add Git Completion To Your Terminal

0
0

This one is a must have! If you use IDEs like IntelliJ IDEA you are used to press magic keys. Here is how you add some magic to the usage of git from your bash terminal. You need the git bash completion. If you use Homebrew and installed git you can start immediately with modifying your bashrc. In my case I change /etc/bashrc.

Git Completion

# add git completion
source /usr/local/etc/bash_completion.d/git-completion.bash

That’s it! Now enjoy the power of the tab-key: Complete git commands, sub-commands, branch names, remotes, …

Git Prompt

The above defines a git prompt as well. You need to add $(__git_ps1 ” %s”) to your prompt.

PS1='\[\e[0;32m\][\w]$(__git_ps1 " %s")\n\u@\h$\[\e[m\] '

Everything between the double-quotes will be displayed in your prompt. The %s will be replaced with the current branch name. Some more information can be
added with flags (see comments in git-completion.bash). I like these:

GIT_PS1_SHOWDIRTYSTATE=true
GIT_PS1_SHOWUPSTREAM="auto"

GIT_PS1_SHOWDIRTYSTATE displays unstaged changes “*” or staged changes “+” next to the branch name. GIT_PS1_SHOWUPSTREAM=”auto” indicates if you are behind “” or diverged ““.

Sample

KYPSTA-2902-hdnCode-for-SecurityProvider is the branch name, I have untracked files and I’m ahead. Cool.

To do a good job we should finish with coloring our terminal.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images