기타 메모

아무 생각 없이 git access token지웠다가 fatal에러 나서 다시 인증해야 할 때 github cli 쓰면 편함

Jonchann 2021. 11. 29. 12:24

제목 그대로 access token만기 됐다고 해서 아무 생각 없이 안쓰는건가 하고 지웠는데 사실은 회사 컴에서 사용하는 애였다.
근데 어쨌든 만기는 됐으니까 새로 갱긴할 필요는 있었으니 큰 문제는 아니다.

참고로 에러는 이런식이다.

$  git pull origin master
hint: Pulling without specifying how to reconcile divergent branches is
hint: discouraged. You can squelch this message by running one of the following
hint: commands sometime before your next pull:
hint: 
hint:   git config pull.rebase false  # merge (the default strategy)
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint: 
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
remote: Repository not found.
fatal: Authentication failed for 'https://github.com/some_repository.git/'

이번에는 github cli를 써 봤는데 간단하고 편했다.
몇가지 골라야 하는 것이 있긴 한데 나는 clone할 때 대체로 HTTPS로 하는 편이라 HTTPS방식을 택했다.
선택지는 2가지씩 나오고 방향키로 골라주기만 하면 된다.

처음에는 항상 하듯이 access token을 새로 발급 받아 인증했는데 이것으로는 한번에 login되지 않았다.

$  gh auth login
? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? HTTPS
? Authenticate Git with your GitHub credentials? Yes
? How would you like to authenticate GitHub CLI? Paste an authentication token
Tip: you can generate a Personal Access Token here https://github.com/settings/tokens
The minimum required scopes are 'repo', 'read:org', 'workflow'.
? Paste your authentication token: ****************************************
error validating token: missing required scope 'read:org'

$ gh auth status
You are not logged into any GitHub hosts. Run gh auth login to authenticate.

그래서 나머지 선택지인 web browser를 열어 인증하는 방식을 택했더니 한번에 인증 성공했다.
따로 access token을 발급받지 않아도 되는지 access token을 먼저 받아놔서 됐는지는 잘 모르겠다.

$  gh auth login
? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? HTTPS
? Authenticate Git with your GitHub credentials? Yes
? How would you like to authenticate GitHub CLI? Login with a web browser

! First copy your one-time code: ****-****  # 실제로는 영문 대문자과 숫자로 인증 코드가 출력됨
- Press Enter to open github.com in your browser... 
✓ Authentication complete. Press Enter to continue...

- gh config set -h github.com git_protocol https
✓ Configured git protocol
✓ Logged in as {user_name}

$  gh auth status
github.com
  ✓ Logged in to github.com as {user_name} (/Users/{user}/.config/gh/hosts.yml)
  ✓ Git operations for github.com configured to use https protocol.
  ✓ Token: *******************