There are a couple of cool features in GIT that may not be well known by everyone, depending on which platform you are using. For example on Linux it is quite common to have the bash completion working, while in Windows msysgit comes with a cool prompt which displays the current branch and some status information on the command line, as well as with the bash completion.
Git (version 1.7.0, and probably 1.7.1) on OS X comes with nothing, so here I show how to enable the command line completion and the git enhanced prompt. You can use the same tip on Linux to get the GIT enhanced prompt.
Here you can see how my prompt looks like:
"luigi@hal9000:~/bin" is my usual prompt (username@hostname:folder), the red part indicates current branch, and the asterisk means that I have some modified files to commit.
In the above sample, also you see what happens when I type "git cl[tab-key]". The tab key triggers command line completion, and I can see available git commands starting with "cl"; in this case clone and clean.
The completion works not only on the command names, but also on file names and git object names, for example on branch names: if you type "git checkout mas[tab-key]" you should get it expaended to "git checkout master".
To enable the GIT bash completion, on OSX, you need to execute the script located at /usr/local/git/contrib/completion/git-completion.bash. This script is installed together with GIT utilities on OSX. To have its features enabled when you open a terminal session you should add following lines to your .profile:
# Set git autocompletion and PS1 integration if [ -f /usr/local/git/contrib/completion/git-completion.bash ]; then . /usr/local/git/contrib/completion/git-completion.bash fi if [ -f /opt/local/share/doc/git-core/contrib/completion/git-prompt.sh ]; then . /opt/local/share/doc/git-core/contrib/completion/git-prompt.sh fi GIT_PS1_SHOWDIRTYSTATE=true if [ -f /opt/local/etc/bash_completion ]; then . /opt/local/etc/bash_completion fi PS1='\[\033[32m\]\u@\h\[\033[00m\]:\[\033[34m\]\w\[\033[31m\]$(__git_ps1)\[\033[00m\]\$ '
The GIT_PS1_SHOWDIRTYSTATE variable is used to indicate that the prompt should display the asterisk or other characters to indicate that the state of the working tree is "dirty" (something is changed and it has not yet been committed).
The script git-completion.bash enables bash completion and contains also some functions that can be executed when the prompt (defined in the PS1 variable) is shown. In this case the function displayed is named __git_ps1 and it displayes the current branch; the rest of the PS1 text is to display a nice prompt with colors.
For Linux user (at least for Ubuntu ones), it is just necessary to define the PS1 variable in the ~/.bashrc file, as the git completion script is usually included by default when installing git.
Another nice trick, that is not enabled by default, is the coloring for the following git commands: branch, status and diff. Having colors enabled helps to faster and easier understand the output. To enable colors issue the following commands:
$ git config --global color.branch auto $ git config --global color.diff auto $ git config --global color.status auto
Configuring above git properties will affect color display as in following examples:
Hope you find those tricks as useful as I do find them.
I also suggest you this article:
Must Have Git Aliases: Advanced Examples
|« Apr||Jun »|
- Android (3)
- Apple (29)
- Books (7)
- Eclipse (14)
- Errors (5)
- Firefox (7)
- Git (3)
- Hardware (18)
- Horror Code (8)
- Internet (21)
- Java (104)
- Life, universe and everything (45)
- Lifehacks (26)
- Linux (52)
- Opinions (26)
- OSX (11)
- OWNER API (2)
- Python (1)
- Software (33)
- Speeches and Conferences (8)
- Unix (5)
- Web (23)
- Windows (19)
Android apple architecture Bash configuration CSS Development Düsseldorf Eclipse Git Google Hardware hdr How-To howto Java JAXB job Karmic Linux lion MacBook music Open Source Opinion OSX os x patterns Pitfalls Practices Resume Security Software Suspend TDD Testing tip tonemapped Tricks Ubuntu unix video Web Workaround XML