상세 컨텐츠

본문 제목

[Git] Clone/Pull/Push 시 계정 묻지 않게 하는 방법

DevOps/Git

by code_down 2024. 6. 27. 19:27

본문

git의 remote repository 를 사용할 때, remote repo 의 주소가 ssl 로 되어있다면 상관없지만, https 로 되어있을 경우 clone,push,pull 드으이 행위에 id/pw 정보를 입력해야하는데 이 과정을 생략하고싶을때 사용할 수 있는 방법을 아래에 기술한다.

 

Credential 

git 에서는 credential 이라는 기능을 제공하는데, 이는 로그인 정보를 저장해 두었다가 재사용하는 기능이다.

해당 기능에는 cache,store,keychain 등의 방법이 있다.

 

Cache

cache 방법은 메모리에 15분 까지 유효한 인증정보(id/pw) 를 저장한다. (짧은 시간만 로그인을 유지할 때)


  
git config --global credential.helper cache # git confg 글로벌 업데이트
git config credential.helper 'cache --timeout=300' #시간을 연장하려면 timeout을 설정한다.

 

Store

store 방법은 Disk 에 인증정보를 저장하고, 저장 정보는 .git-credentials 파일에 기록된다. (인증을 계속 유지할 때)


  
git config --global credential.helper store

 

Keychain

store 방식은 파일에 인증정보 기록되는데 이를 좀 더 안전하게 저장하기 위해 os에서 지원하는 keychain 시스템을 이용할 수 있다. (사용하던 remote repo 의 정보를 변경할 경우, os 자격 증명 관리자를 통해 정보를 삭제해야한다.)


  
git config --global credential.helper wincred #for windows
git config --global credential.helper osxkeychain #for mac

 

설정된 Credential 정보 확인 방법


  
git config --global --list #전역
git config --list #로컬
# > credential.helper=store

 

그 외 방법

remote repo 주소에 접속정보를 입력해 줄 수 있다. 하지만 인증정보가 노출되게 되므로 위험할 수 있다.

(personal access token을 생성하여 사용하자)


  
git clone https://<ID>:<PersonalAccessToken>@myrepo.github.com/project.git