Code

git-open 사용하기

September 1, 2016

author:

Array

git-open 사용하기

아는 분이 git-open을 소개해주셔서 사용해보기 시작했는데
꽤 마음에 들어서 소개글을 작성해봅니다.

이 툴은 터미널에서 저장소 홈페이지를 바로 열 수 있게 해주는 툴입니다.
Github, Gist, Gitlab, bitbucket을 지원합니다. 설명보다는 실제 예제를 봅시다.

Install

npm 패키지이므로 다음과 같이 설치합니다.

$ npm install -g git-open

사용법

기본

# 현재 브랜치 issue-32
$ git open
# https://github.com/user/repo/tree/issue-32

Git으로 관리되고 있는 프로젝트 내에서 실행하면 해당하는 프로젝트의
페이지를 열어줍니다.

특정 리모트

# remote의 upstream 이 https://github.com/some_user/repo 를 보고 있을 때
$ git open upstream
# https://github.com/some_user/repo/

리모트의 브랜치

# remote의 upstream 이 https://github.com/some_user/repo 를 보고 있을 때
$ git open upstream issue-32
# https://github.com/some_user/repo/tree/issue-32

이슈 열기

# 현재 브랜치가 issues/#111 일 때
$ git issue
# https://github.com/some_user/repo/issues/111 또는
# https://github.com/some_user/repo/pull/111

귀찮다…

편하긴 한데 이슈명의 컨벤션이 현재 쓰고 있는 거(i{issue number})랑
다릅니다. 저는 issues/#111 같은 브랜치 이름을 사용할 생각도 없고,
매우매우 귀찮았기 때문에 다음과 같이 좀 고쳤습니다.

# 생략
    regex='^i'
    if [[ $currentBranch =~ $regex ]]; then
      issue=${currentBranch#*i}
    else
      echo "'git open issue' expect branch naming to be i123" 1>&2
      exit 1
    fi
# 생략

분명 i로 시작하는 다른 브랜치가 생기면 문제가 되겠지만,
그런 브랜치는 만들지 않으니 괜찮을 겁니다. XD

결론

cmd에서 git을 사용하는 당신에게 선물! 깃헙에 좀 더 편하게 접속합시다!

참고 자료

git-open

Array