1 Go to your home directory
CD ~
2 Edit. bashrc file
VI. BASHRC
3 Add the following code to the end of the file
function git_branch { Branch= "' Git branch 2>/dev/null | grep" ^\* "| sed-e" s/^\*\//"'" if ["${bra NCH} "! =" " ];thenif [" ${branch} "=" (No branch) " ];then Branch=" (' Git rev-parse--s Hort HEAD ' ...) ' fi "($branch)" fi}export PS1= ' \[email protected]\h \[\033[01;36m\]\w\[\033[ 01;32m\]$ (git_branch) \[\033[00m\] \$ '
4 Save Exit
5 Executing the load command
source./.BASHRC
6 Complete
The shell launched under MAC is the login shell, so the configuration file loaded is. bash_profile and will not load. BASHRC. If you're a MAC user, you'll need to execute the following command, which will automatically take effect every time you turn it on:
echo "[-R ~/.BASHRC] && source ~/.BASHRC" >>. Bash_profile
MAC, Linux system terminal shows git current branch