반응형
이번에는 .gitconfig
을 이용하여 clone시 remote url을 https 혹은 ssh로 바꾸게 만들어서 편하게 git url을 설정할 수 있는 방법을 알아보겠습니다.
설정할 수 있는 gitconfig 세 가지 입니다.
또한, 각 설정은 .git/config > ~/.gitconfig > /etc/gitconfig 순으로 우선시 됩니다.
1. /etc/gitconfig 파일
시스템의 모든 사용자와 모든 저장소
에 적용되는 설정 파일입니다.- 이 파일은 시스템 전체 파일에 대한 설정이기 때문에 수정하려면 시스템의 관리자 권한이 필요합니다.
$ git config --system
https -> ssh로 사용하기
// git fetch or git push url
git config --system url.ssh://git@github.com/.insteadOf https://github.com/
// git push url
git config --system url.ssh://git@github.com/.pushInsteadOf https://github.com/
ssh -> http로 사용하기
// git fetch or git push url
git config --system url.https://github.com/.insteadOf ssh://git@github.com/
// git push url
git config --system url.https://github.com/.pushInsteadOf ssh://git@github.com/
2. ~/.gitconfig 파일
현재 사용자
에게만 적용되는 설정 파일입니다.$ git config --global
https -> ssh로 사용하기
// git fetch or git push url
git config --global url.ssh://git@github.com/.insteadOf https://github.com/
// git push url
git config --global url.ssh://git@github.com/.pushInsteadOf https://github.com/
ssh -> http로 사용하기
// git fetch or git push url
git config --global url.https://github.com/.insteadOf ssh://git@github.com/
// git push url
git config --global url.https://github.com/.pushInsteadOf ssh://git@github.com/
3. .git/config 파일
특정 저장소
에만 적용되는 설정 파일입니다.- 특정 저장소의 .git 디렉토리의 config 파일을 수정하면 됩니다.
$ git config --local
https -> ssh로 사용하기
// git fetch or git push url
git config --local url.ssh://git@github.com/.insteadOf https://github.com/
// git push url
git config --local url.ssh://git@github.com/.pushInsteadOf https://github.com/
ssh -> http로 사용하기
// git fetch or git push url
git config --local url.https://github.com/.insteadOf ssh://git@github.com/
// git push url
git config --local url.https://github.com/.pushInsteadOf ssh://git@github.com/
url을 ssh -> https로 바꾸도록 적용한 후의 ~/.gitconfig 파일
url을 https -> ssh로 바꾸도록 적용한 후의 ~/.gitconfig 파일
적용후에는 git clone을 하거나 url을 수정할 지라도 .gitconfig에서 설정했던 프로토콜로 수정됩니다.
반응형