Skip to content

Recommended git setup

Bill Sacks edited this page Oct 6, 2017 · 25 revisions

There are two helpful things you can do to streamline your use of git if you use the bash shell. These are also documented here: https://git-scm.com/book/en/v2/Appendix-A%3A-Git-in-Other-Environments-Git-in-Bash

With bash, many command-line tools support smart tab-completion, so that (for example) if you type git ch[Tab], you will get a list of possible completions; if there is only one possible completion (e.g., git chec[Tab]), it will be filled in for you.

On a mac, if you use homebrew, you can install bash completion for many commands with brew install bash-completion, and there are probably similar things you can do on other systems.

To just install bash completion for git, you can copy https://github.com/git/git/blob/master/contrib/completion/git-completion.bash to some location on your system, then add the following to your .bashrc file:

source /path/to/git-completion.bash

It can sometimes be hard to keep track of the state of your working copy: you could have changes that are committed but not yet pushed, changes that have been staged but not committed, and/or changes that have not yet been staged. There are git commands to show you these things, but it can be more convenient to have that information right in front of you in your terminal at all times. This is where "git prompt" comes in.

For example, I have configured my prompt to look like this:

Clone this wiki locally