본문 바로가기
개발/Git, GitHub

Git Bash - fetch / pull 할 때 ID, Password 자동 입력하기

by 피로물든딸기 2024. 3. 1.
반응형

Git / GitHub 전체 링크

 

참고

- https://git-scm.com/docs/git-credential-cache

- 개인 토큰 발급 받기 (Personal access tokens)

 

깃허브의 저장소를 자동으로 sync하려면 fetch / pull 명령어를 하면 된다.

git fetch origin main
git stash
git pull origin main

 

하지만 fetch를 할 때, 아래와 같이 UsernamePassword를 매번 입력해야 한다.

 Username for 'https://github.com': 
 Password for 'https://github.com :

해결 방법

 

먼저 git config에서 name과 password를 설정하자.

$ git config --global user.name "bloodstrawberry"
$ git config --global user.password "mypassword"

 

--list 옵션으로 설정된 정보를 확인할 수 있다.

$ git config --list

...
user.email=bloodstrawberry@hanmail.net
user.name=bloodstrawberry
user.password=mypassword
...

 

여기서 credential.helper의 store 옵션을 이용하면 namepassword계속 저장하게 된다.

git config --global credential.helper store

 

다시 --list 옵션을 이용해 credential 설정을 확인해 보자.

$ git config --list

...
user.email=your_email
user.name=bloodstrawberry
user.password=mypassword
...
credential.helper=store

 

이제 fetch / pull을 할 경우 name과 password를 묻지 않는다.

 

만약 인증 정보를 100분 동안 유지하고 싶다면 cache 옵션을 사용하면 된다.

git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=6000'

 

credential 설정을 지우고 싶다면 unset 옵션을 사용하면 된다.

git config --unset --global credential.helper

 

그리고 비밀번호가 바뀌는 경우 위의 설정을 다시 해야 한다.

깃허브에서 만료 기한이 없는 토큰을 발급 받으면 password 대신 설정할 수 있다.

$ git config --global user.password "yout_personal_access_token"
반응형

댓글