Adding git branch on the Bash command prompt

前端 未结 13 2098
感情败类
感情败类 2020-11-30 16:15

I tried adding the git branch I\'m currently working on (checked-out) on the bash prompt without success.. (while keeping my current path which shows the active dir

13条回答
  •  难免孤独
    2020-11-30 16:58

    1- If you don't have bash-completion ... : sudo apt-get install bash-completion

    2- Edit your .bashrc file and check (or add) :

    if [ -f /etc/bash_completion ]; then
      . /etc/bash_completion
    fi
    

    3- ... before your prompt line : export PS1='$(__git_ps1) \w\$ '
    (__git_ps1 will show your git branch)

    4- do source .bashrc

    EDIT :

    Further readings : Don’t Reinvent the Wheel

提交回复
热议问题