개발이야기
shell 프롬프트에 git branch 표시하기. git 커맨드 자동완성
준호씨
2017. 10. 2. 11:35
반응형
2018.11.01 내용 분리
shell 프롬프트에 git branch 표시하기 http://junho85.pe.kr/1150
우선 .git-completion.bash .git-prompt.sh 파일이 있어야 한다. .git-completion.bash 는 자동완성을 위한 것이고 .git-prompt.sh 는 프롬프트에 branch 정보를 표시하기 위함이다.
해당 파일들은 아래 경로에서 받을 수 있다. https://github.com/git/git/blob/master/contrib/completion/git-completion.bash https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
~/.bashrc 설정
~/.bashrc 를 다음과 같이 설정 한다.
source ~/.git-completion.bash
source ~/.git-prompt.sh
export PS1="\[\e[31m\]\u\[\e[0m\]@ \h:\${PWD} [\t]\\$\$(__git_ps1) "
PS1 은 예시일 뿐이고 중요한 부분은 __git_ps1 부분이다. PS1 을 위처럼 설정한 경우
# git 디렉토리인 경우
junho85@ junho85:/somewhere_git [17:41:35]$ (master)
# 일반 디렉토리
junho85@ junho85:/somewhere [17:41:35]$
처럼 나온다.
자동완성
git co
$ git pu
pull -- fetch from and merge with another repository or a local branch
push -- update remote refs along with associated objects
git checkout
$ git checkout
FETCH_HEAD HEAD ORIG_HEAD master origin/master
참고
https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
반응형