본문 바로가기

Technical/Development

[Git Tip] Git Branch와 상태를 보여주는 Linux Prompt(bash-git-prompt)


지난 번 Git 을 위한 Linux Prompt 변경 내용에 추가하여, Github.com 프로젝트 중에서 쓸만 한 것이 있어서 소개해 두도록 한다. 단순히 Branch 명을 보여 주는 것에서 벗어나서 브랜치의 자세한 상태까지 Prompt 에서 보여 주므로 아주 실속 있는 Git용 프람프트 유틸리티가 아닐까 한다. 설치 과정도 아주 간단하여 쉽게 적용해 볼 수 있다.


* 적용 대상: Bash를 사용하는 Linux 또는 Mac

* 설치 방법: https://github.com/magicmonty/bash-git-prompt 에 있는 내용 참조







* 설치 과정(Ubuntu 14.04, Bash 사용)

bryan@bryan-XenPC:~cd ~

bryan@bryan-XenPC:~git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt

bryan@bryan-XenPC:~$ vi .bashrc <== .bashrc 의 case "$TERM" ... 문 다음의 적당한 위치에 추가

...

# If this is an xterm set the title to user@host:dir

case "$TERM" in

xterm*|rxvt*)

    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

    ;;

*)

    ;;

esac


# gitprompt configuration

# Set config variables first

GIT_PROMPT_ONLY_IN_REPO=1

# GIT_PROMPT_FETCH_REMOTE_STATUS=0   # uncomment to avoid fetching remote status

# GIT_PROMPT_START=...    # uncomment for custom prompt start sequence

# GIT_PROMPT_END=...      # uncomment for custom prompt end sequence

# as last entry source the gitprompt script

# GIT_PROMPT_THEME=Custom # use custom .git-prompt-colors.sh

# GIT_PROMPT_THEME=Solarized # use theme optimized for solarized color scheme

source ~/.bash-git-prompt/gitprompt.sh


# enable color support of ls and also add handy aliases

...

bryan@bryan-XenPC:~$ source .bashrc


* ~/.bash-git-prompt/themes 내에 테마파일을 설정해 두고 커스텀 테마를 지정해서 사용할 수도 있다

* 다음은 bash-git-prompt 프로젝트 홈에 소개 된 프롬프트 심볼들에 대한 간단한 설명들이다


[Local Status Symbols] 로컬브랜치 상태 심볼들

    ✔: repo가 더 이상 건드릴 부분 없이 clear 함

    ●n: n개의 staging된(index 에 add되었지만 commit은 되지 않은) 파일들이 있음

    ✖n: n개의 merge 되지 않은 파일들이 있음

    ✚n: n개의 수정되었지만 staging되지 않은(add가 필요한) 파일들이 있음

    …n: n개의 트래킹 되지 않은 파일들이 있음

    ⚑n: n개의 스태쉬(임시 저장소)가 존재함


[Branch Tracking Symbols]리모트저장소와 비교된 트래킹 심볼들

    ↑n: 리모트저장소보다 n개의 commit 단계가 앞서 있음(push 가 필요한 상태 암시)

    ↓n: 리모트저장소보다 n개의 commit 단계가 거슬러 내려가 있음

    ↓m↑n: 리모트저장소에 비해 브랜치가 갈라져 있음, 위 2가지가 복합됨

     L: 로컬브랜치만 존재함


[관련 글]

2015/07/23 - [Git Tip] AWS EC2 VM을 이용한 Git 서버설정과 git 기본 사용법

2015/07/24 - [Git Tip] Git에 대한 궁금증들

2015/07/31 - [Git Tip] Git 브랜치를 보여주는 Linux 프람프트(prompt) - Ubuntu 14.04, bash 기준


- Barracuda -