PromleeBlog
sitemap
aboutMe

posting thumbnail
하나의 Repository에 여러 개의 remote repository를 관리하는 방법
How to manage multiple remote repositories in one repository

📅

🚀

들어가기 전에 🔗

이 포스팅은 Mac 환경에서 작성되었습니다.
때로는 하나의 프로젝트 폴더에서 여러 개의 remote repository를 관리해야 할 때가 있습니다. 예를 들어, 같은 프로젝트를 서로 다른 클라이언트에게 제공해야 할 때가 있습니다. 이럴 때 하나의 프로젝트 폴더에서 여러 개의 remote repository를 관리하는 방법을 알아보도록 하겠습니다.

🚀

1. 첫번째 remote repository 추가 🔗

일단 빈 프로젝트 폴더를 하나 만들어 주세요.
mkdir project-folder
github에서 미리 생성된 레포지토리의 remote repository url을 복사해 주세요.
240606-154630
240606-154630
그리고 첫번째 remote repository를 추가해 주세요. 이 때, 복사해 둔 remote repository url을 사용해 주세요.
git remote add origin https://github.com/user/first-repo.git

🚀

2. 두번째 remote repository 추가 🔗

github에서 추가로 레포지토리를 생성한 후 해당 remote repository url을 사용해 주세요.
두번째 remote repository를 추가해 주세요. 이 때에는 origin이 아닌 다른 이름을 사용하는 것을 권장합니다. 만일 origin이라는 이름을 사용하면 모든 작업이 두 개의 remote repository에 동시에 적용되어 버립니다.
필자는 두번째 remote repository의 이름을 second-remote로 지정했습니다.
git remote add second-remote https://github.com/user/second-repo.git

🚀

3. 적용 확인 🔗

cmd에서 프로젝트 폴더로 이동 후 다음 명령어를 입력해 주세요.
git remote -v
예시로 다음과 같이 출력됩니다.
origin  https://github.com/user/first-repo.git (fetch)
origin  https://github.com/user/first-repo.git (push)
second-remote  https://github.com/user/second-repo.git (fetch)
second-remote  https://github.com/user/second-repo.git (push)

🚀

4. 브랜치 이동 및 푸시, 풀 🔗

두 개의 remote가 연결되어 있기 때문에 브랜치를 이동할 때 remote의 이름을 지정해 주어야 합니다.
git checkout second-remote/main
브랜치를 이동한 후 작업을 진행해 주세요.
git add .
git commit -m "commit message"
git push second-remote main
물론 두 개의 remote 브랜치에 동시에 push 도 가능합니다.
git push origin main
git push second-remote main
pull 하는 경우에도 마찬가지로 remote의 이름을 정확하게 지정해 주어야 합니다.
git pull origin main
git pull second-remote main

🚀

5. remote repository 삭제 🔗

remote repository를 삭제하고 싶다면 다음 명령어를 입력해 주세요.
git remote remove origin
git remote remove second-remote

🚀

결론 🔗

한 개의 프로젝트 폴더에 여러 개의 remote repository를 관리하는 방법을 알아보았습니다. 이 방법을 사용하면 여러 개의 remote repository를 관리하는 것이 훨씬 수월해집니다.

참고 🔗