11

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?

2
  • 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, 2012 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 Jul 25, 2012 at 20:25

5 Answers 5

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.

2
  • 1
    So exactly what i should do to activate this on uBuntu? :) Sorry but i'm new. Jul 27, 2012 at 12:35
  • Go to the Home directory and type the command in terminal as "gedit .baschr" and you will prompt to edit the .baschr file.But make sure to have a original copy in a different directory for safety. Feb 7, 2017 at 2:27
4

For color:

git config --global color.ui true
1

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.

1
  • 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
0
0

Here's how to add windows-like git-bash to Ubuntu terminal:

  1. Add to the end of ~/.bashrc:
    PS1='\[\033]0;$MSYSTEM:${PWD//[^[:ascii:]]/?}\007\]\n\[\033[32m\]\u@\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$ '
  2. execute in terminal: source ~/.bashrc

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .