PS1="\\w (`git branch | grep '^*' | cut -b 3-100`)$ "
I set my PS1 as above, but it will not update the branch name in the prompt after I change the branch with git checkout
, or change the repository with the cd
. How to fix this?
In Git, the git branch branch-name command is used to create a new branch called branch-name . Branches should be named something that describes the purpose of the branch. Note that branch names can't contain whitespace: new-feature and new_feature are valid branch names, but new feature is not.
New Branches The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.
The git branch command lets you create, list, rename, and delete branches. It doesn't let you switch between branches or put a forked history back together again. For this reason, git branch is tightly integrated with the git checkout and git merge commands.
The backtick-quoted bit is evaluated when PS1
is set (once), not when the prompt is displayed. Use single quotes to save the expansion for the latter event:
PS1='\w (`git branch | grep "^*" | cut -b 3-100`)$ '
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