잡동사니/개발관련
Linux shell 내 branch name 표시
Jayyy.H
2020. 10. 12. 16:00
Intro
개발을 하며 git branch -a
를 이용해 현재 branch는 무엇인지 확인할 일이 많다.
하지만 이렇게 매번 branch name을 확인하기 위해 동일한 명령어를 반복적으로 쓰는것은 매우 번거로운 일이 아닐 수 없다.
따라서 다음의 과정을 통해 Shell 내에서 branch name을 자동으로 표시할 수 있도록 하자.
How to
아래 명령어는 Ubuntu 20.04를 기준으로 수행되었습니다.
gedit ~/.bashrc
스크롤을 내려 가장 아래에
parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' } export PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
입력
terminal 재 시작
Result
그러면 아래의 사진과 같이 Linux shell에 branch name이 표시된 것을 볼 수 있다.
Reference
ask ubuntu - How do I show the git branch with colours in Bash prompt?