Show the name of the branch you are in at the prompt
-
Open your terminal
-
Edit the .bashrc file
user@mypc:~$ vim ~/.bashrc
- At the end of the file add the following lines:
show_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h:\[\033[32m\]\w\[\033[36m\]\$(show_git_branch)\[\033[00m\]$ "
-
Save the file
-
Redirect to a directory where you have a repository and you will see the changes
user@mypc:~$ cd apps/show_git_branch
user@mypc:~/apps/show_git_branch (main)$