Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying git branch name in prompt does not work in screen

Tags:

I updated my .bashrc file as follows:

PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$' 

It works just find and I can see my branch name in the prompt. However,when I run "screen" , I get

"-bash: __git_ps1: command not found"

What can be the reason for this?

like image 209
Ohad Avatar asked Mar 15 '12 09:03

Ohad


People also ask

How do I make a git branch visible in Terminal?

The git_branch() is a function, that prints the name of the current Git branch in the round brackets. We set the PS1 variable and place the function git_branch() inside it to display the Git branch in the terminal prompt.

Why git branch is not showing all branches?

This can happen if your repo has 0 commits. If you make a commit, your current branch will appear when you do: git branch . Show activity on this post. Sounds like you have a permission issue.


1 Answers

This blog post explains that you have to add the line source /etc/bash_completion.d/git before you can use __git_ps1.

Here is the full example:

source /etc/bash_completion.d/git   export PS1='\w$(__git_ps1 "(%s)") > ' 

This also enables auto completion for branches.

Using that formatting, your prompt will resemble (without colouring):

~/my-repo(master) >  
like image 134
SeriousM Avatar answered Oct 16 '22 13:10

SeriousM