회사와 개인프로젝트의 계정을 분리한다던지, 개인 프로젝트와 스터디 그룹의 계정을 분리한다던지 한 컴퓨터에서 여러 Github 계정을 사용해야 할 경우가 있다. SSH를 활용하여 관리하는 방법을 사용하면 편하다.

기존에 ssh 키가 있는지 확인

  ls -al ~/.ssh

ssh 키를 생성 및 agent 등록

  # 2개의 키 생성하기
  ssh-keygen -t rsa -C "{private}@mail.com" -f "~/.ssh/{rsa file for private}"
  ssh-keygen -t rsa -C "{group}@mail.com" -f "~/.ssh/{rsa file for group}"

  # 키 생성 확인
  ls -al ~/.ssh

  # ssh-agent 실행 확인
  eval "$(ssh-agent -s)"

  # 생성한 키 등록
  ssh-add ~/.ssh/{rsa file for private}
  ssh-add ~/.ssh/{rsa file for group}

  # 등록한 키 확인
  ssh-add -l
  4096 SHA256:... {private}@mail.com (RSA)
  4096 SHA256:... {group}@mail.com (RSA)

ssh 설정 파일 수정

ssh 설정 파일은 ~/.ssh/config이다. 파일이 존재하지 않는다면 생성 후 진행한다.

  # 파일 존재 여부 확인
  cat ~/.ssh/config

  # 파일 생성
  touch ~/.ssh/config

  # 파일 수정
  vi ~/.ssh/config
  # IDLOOK
  Host github.com-{group_name}
    HostName github.com    
    User {group_github_name}
    IdentityFile ~/.ssh/{rsa file for group}

  # PRIVATE
  Host github.com-{private_name}
    HostName github.com
    User {private_github_name}
    IdentityFile ~/.ssh/{rsa file for private}

git 설정파일 수정

git user name과 user email 설정 파일을 각각 생성 수정한다

  touch ~/.gitconfig-{private}
  touch ~/.gitconfig-{group}

개인용

  vi ~/.gitconfig-{private}
  [user]
    name = {private_github_name}
    email = {private}@mail.com

업무용

  vi ~/.gitconfig-{group}
  [user]
    name = {group_github_name}
    email = {group}@mail.com

git 설정 파일에서 해당 파일을 읽어오도록 한다

  vi ~/.gitconfig
  [includeIf "gitdir:{개인 프로젝트 경로}"]
    path = .gitconfig-{private}
  [includeIf "gitdir:{그룹 프로젝트 경로}"]
    path = .gitconfig-{group}

Github 계정에 SSH 키를 등록

생성한 ssh 키를 각각 두개의 github 계정에 등록해준다.

우측 상단 Github Profile > Settings > 좌측 SSH and GPG keys > 우측상단 New SSH Key
타이틀은 편하게, Key type은 Authentication Key, Key 부분에 생성한 키를 복사해서 붙여 넣는다.

  # shell에서 명령어로 복사하는 방법
  pbcopy < ~/.ssh/{rsa file for private}

  # shell에서 명령어로 출력한 후 terminal에서 복사하는 방법
  cat ~/.ssh/{rsa file for private}

Github 등록 확인

  ssh -T git@github.com-{private_name}

로컬로 Github 레포지토리 복사

복사시 https가 아닌 ssh로 한다

  git clone git@github.com-{private_name}:{user-name}/{repository-name}.git

로컬이 이미 레포지토리가 있을 경우 주소 변경

  # 기존 리모트 url 확인
  git config --get remote.origin.url
  git@github.com:{A}/{B}.git
  # 리모트 url 변경
  git remote set-url origin git@github.com-{private_name}:{A}/{B}.git

  # 동작 확인
  git pull

clone, pull등 git 명령어 결과에서 에러가 나올 경우 ssh를 디버깅 모드로 시도

  GIT_SSH_COMMAND="ssh -v" git fetch

DL;DR

모든 내용은 git manual에 있다.https://git-scm.com/docs/git-config#_conditional_includes

참고

728x90
반응형

'VCS' 카테고리의 다른 글

[GIT]  (0) 2024.04.10
[VCS] 좋은 커밋 메세지 간단 작성법  (0) 2023.07.14
[GIT] 브랜치, 커밋 간 다른 파일 목록 조회  (0) 2022.04.05
[GIT] remote branch 가져오기  (0) 2022.04.05
[TortoiseSVN] Disconnect 방법  (0) 2021.09.10

윈도우 버전 GIT 설치하기

  1. Git 설치 파일을 다운
    git download

 

Git - Downloads

Downloads Mac OS X Windows Linux/Unix Older releases are available and the Git source repository is on GitHub. GUI Clients Git comes with built-in GUI tools (git-gui, gitk), but there are several third-party tools for users looking for a platform-specific

git-scm.com

  1. 설치 시작 NEXT

  1. NEXT

  1. NEXT

  1. NEXT

  1. NEXT

  1. NEXT

  1. NEXT

  1. NEXT

  1. NEXT

  1. 설치 진행

  1. 설치 완료

  1. git에 사용자의 이름과 이메일 설정 후 설정 확인

    git config --global user.name '사용자 이름'
    git config --global user.email '이메일 주소'
    git config --list

     

  1. github에서 repository clone

  1. clone 한 repository open

  1. 간단한 수정 후 commit 시도

  1. github login

  1. 로그인 후 commit 성공

728x90
반응형

'VCS' 카테고리의 다른 글

[GIT]  (0) 2024.04.10
[VCS] 좋은 커밋 메세지 간단 작성법  (0) 2023.07.14
[GIT] 브랜치, 커밋 간 다른 파일 목록 조회  (0) 2022.04.05
[GIT] remote branch 가져오기  (0) 2022.04.05
[TortoiseSVN] Disconnect 방법  (0) 2021.09.10

# HTML에 GitHub Contribution Calendar 삽입하는 방법.

<!-- Prepare a container for your calendar. -->
<script src="https://cdn.rawgit.com/IonicaBizau/github-calendar/gh-pages/dist/github-calendar.min.js"></script>

<!-- Optionally, include the theme (if you don't want to struggle to write the CSS) -->
<link rel="stylesheet" href="https://cdn.rawgit.com/IonicaBizau/github-calendar/gh-pages/dist/github-calendar.css"/>

<!-- Prepare a container for your calendar. -->
<div class="calendar">
    <!-- Loading stuff -->
    Loading the data just for you.
</div>

<script>
    new GitHubCalendar(".calendar", "your-username");
</script>

이 소스코드에서 `"your-usernamne"`부분에 github 이름을 넣어준다.

결과는 내 블로그 하단에...

728x90
반응형

+ Recent posts