Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

When I use Windows, the shell (even a standard Windows shell) shows basic information about the git repository when you are in a git repository. Things like the active branch and maybe some color coding.

Is there a way to have the same in Ubuntu?

share|improve this question
    
what version of git do you have installed in windows? What commands do you run to get this information? Have you tried those commands with the git-core package installed? –  jackweirdy Jul 25 '12 at 20:22
    
On git i have the latest version, but simply if i use the command line and i'm inside a git repository, i see the name of the active branch –  Nicola Peluchetti Jul 25 '12 at 20:25

4 Answers 4

The Windows Git shell, which is really just bash, sets the prompt $PS1 to a long string that includes $(__git_ps1).

__git_ps1 is defined as a function, nearly 100 lines long, that prints the name of the current branch in parentheses.

/etc/profile (which is C:\Program Files (x86)\Git\etc\profile, at least on my system)) invokes /etc/git-completion.bash, which defines the __git_ps1 function, sets $PS1, defines some git-specific completions, among other things.

The git-completion.bash used by Git Bash appears to be based on this.

share|improve this answer
1  
So exactly what i should do to activate this on uBuntu? :) Sorry but i'm new. –  Nicola Peluchetti Jul 27 '12 at 12:35

For color:

git config --global color.ui true
share|improve this answer

If you use zsh as your shell, you might find my config files useful. Try source prompt/blocky to see what the prompt looks like in a Git repository.

share|improve this answer
  • How to stop bash prompt colours from escaping has an example. You could copy it from the answer and then use gedit to paste it to the bottom of your the .bashrc file in your home directory (making a backup, first, of course).

  • If the .bashrc file Keith mentions in his answer is part of git it will be licensed with GPL2 so you should be free to past it into your .bashrc file as well. You'll have to grab the /etc/git-completion.bash file and install it somewhere too, and have your new .bashrc reference it.

  • Here's something else you could paste and try from Arturo Fernandez at http://www.bsnux.com/recipes/how-display-you-current-git-branch-prompt.html

 # Displaying git branch inside prompt
 function parse_git_branch {
   git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
 }

 function proml {
   local       GREEN="\[\033[0;32m\]"
   local       WHITE="\[\033[0;37m\]"

 PS1="[\u@\h \w$GREEN\$(parse_git_branch)]$WHITE\$ "
 PS2='> '
 PS4='+ '
}
proml
share|improve this answer
    
Thanks go to Arturo for licensing this with CC. –  John S Gruber Aug 13 '12 at 0:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.