[GIT] .gitconifg 설정으로 remote URL을 ssh 혹은 https로 사용하도록 만들기

2022. 5. 19. 10:17·DevOps/GIT
반응형

이번에는 .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로 강제

url을 https -> ssh로 바꾸도록 적용한 후의 ~/.gitconfig 파일

 

적용후에는 git clone을 하거나 url을 수정할 지라도 .gitconfig에서 설정했던 프로토콜로 수정됩니다.

 

반응형
'DevOps/GIT' 카테고리의 다른 글
  • [Git] git reflog를 이용하여 git reset --hard로 지워진 커밋 복구하기
  • [Git] git commit --amend로 마지막 커밋 수정하기
  • [Git] Git Rebase란? (feat. git-flow 히스토리를 더 이쁘게 만들기)
seunghwaan
seunghwaan
공부한 내용을 정리하는 개발 기록 블로그
    반응형
  • seunghwaan
    SH's Devlog
    seunghwaan
  • 전체
    오늘
    어제
    • 분류 전체보기 (150)
      • Android (62)
        • Basic (17)
        • Kotlin(Java) (14)
        • UI & Animation (1)
        • Compose (2)
        • Coroutines (1)
        • Dependency Injection (6)
        • RxJava (8)
        • BLE (3)
        • TDD (2)
        • JetPack (1)
        • NextStep (4)
        • Error Log (3)
      • Flutter (14)
        • Basic (5)
        • Dart (1)
        • State Management (2)
        • Widgets (4)
        • Error and Tips (2)
      • iOS (8)
        • Basic (0)
        • Swift (8)
      • Web Frontend (6)
        • Basic (0)
        • JavaScript (5)
        • TypeScript (0)
        • React (1)
      • CS(Computer Science) (18)
        • Network (4)
        • Database (10)
        • Design Pattern (1)
        • Computer Architecture (3)
        • Operating System (0)
      • Cloud (6)
        • AWS (6)
      • DevOps (25)
        • GIT (4)
        • CI CD (8)
        • Linux (4)
        • Docker (9)
        • Error Log (0)
      • 코딩테스트 (10)
        • DB (6)
        • 알고리즘 (4)
      • Backend (1)
        • Spring (1)
      • Mac Tip (0)
      • Language (0)
        • English (0)
        • Japanese (0)
      • Temporary (0)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    CI
    AWS
    Algorithm
    Dependency Injection
    Linux
    Swift
    Dagger
    MySQL
    BLE
    FLUTTER
    RxJava
    error
    Computer Science
    시작하세요! 도커
    컴퓨터공학
    cs
    docker
    Kotlin
    상태 관리
    Network
    Android
    gradle
    JavaScript
    IOS
    di
    database
    cognito
    네트워크
    Jenkins
    CICD
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.6
seunghwaan
[GIT] .gitconifg 설정으로 remote URL을 ssh 혹은 https로 사용하도록 만들기
상단으로

티스토리툴바