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?
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.
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.
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) >
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With