[github] terminal에서 github cli 사용하기 (feat. gh)

dev stefanCho·2022년 5월 7일
0

git

목록 보기
13/14

유튭을 보다가 우연히 gh라는 cli에 대해서 알게 되었습니다.
매번 깃헙에 접속하여 작업을 했는데, 저는 터미널을 선호하므로 gh에 대해서 알아보겠습니다.
아래 사용하는 모든 cli는 여기에 모두 있습니다.

gh로 로그인하기

gh를 사용하기 위해서는 우선 gh로 로그인을 해야합니다.

gh auth login

그리고, 나오는 질문들에 대해서는

? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? SSH
? Upload your SSH public key to your GitHub account? /Users/Owner/.ssh/id_rsa.pub
? How would you like to authenticate GitHub CLI? Login with a web browser

로 해줍니다. (만약 ssh키를 깃헙에 이미 등록한 상태라면 아래와 같은 에러가 발생할 것이지만, 문제되지 않습니다.

HTTP 422: Validation Failed (https://api.github.com/user/keys)
key is already in use

로그인 상태확인

gh auth status

repo 리스트 확인하기

gh repo list # 기본적으로 30개를 보여줍니다.
gh repo list -L 100 # repo를 100개까지 보여줍니다.

repo 생성하기

저는 github에 테스트용 repo를 가끔 만드는데요, 이걸로 생성하고 삭제하면 너무 편할것 같습니다.

gh repo create gh-test --public -c

-c로 repo를 만들고 현재 directory에 바로 clone을 합니다.
--public로 public repo를 생성합니다.

pr 생성하기

gh pr create --web

pr 생성 web페이지를 바로 열어줍니다.

gh pr create

terminal에서 바로 pr을 할 수도 있습니다.
Body부분은 기본은 nano로 작성하게 되어있습니다. vim으로 바꾸려면 아래 커맨드를 입력합니다.

gh config set editor vim

pr list 확인하기

방금 생성한 pr을 확인해봅니다.

gh pr list

pr 내용 web에서 확인하기

gh pr view # 상세내용까지 확인
gh pr view 2 --web 

2번 pr을 web에서 열기

pr 내용 로컬로 가져오기

gh pr checkout 2 # 2번 pr을 로컬로 가져옵니다.

로컬에서 해당 branch로 checkout을 바로 해줍니다.

remote branch 삭제하기

gh 명령어는 아니지만, pr 완료후, remote branch를 삭제하는 경우를 위해 참고용으로 기록합니다.
(아래 두가지 명령은 동일합니다.)

git push <remote_name> :<branch_name>
git push <remote_name> --delete <branch_name>

보통 remote_name은 origin 입니다.

git push origin :develop

repo 삭제하기

gh repo list # list를 확인하고
gh repo delete gh-test # repo를 삭제합니다.

? Type devstefancho/gh-test to confirm deletion: 라고 뜨는데, devstefancho/gh-test를 그대로 입력하면 삭제가 됩니다.

gh repo clone

gh repo clone <OWNER/REPO_NAME>

위와 같은 형태로 클론을 받을 때

The authenticity of host 'github.com (52.78.231.108)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names

라고 나온다면 yes를 한다.

profile
Front-end Developer

0개의 댓글