development

프로젝트가 여러 출처를 가질 수 있습니까?

big-blog 2020. 6. 13. 09:28
반응형

프로젝트가 여러 출처를 가질 수 있습니까?


프로젝트가 Git에 두 개 이상의 "원점"을 가질 수 있습니까?

하나의 프로젝트를 githubHeroku 서버 에 푸시하고 싶습니다 .

특히 github 저장소를 추가 할 때이 오류가 나타납니다.

$ git remote add origin https://github.com/Company_Name/repository_name.git
fatal: remote origin already exists.

원하는만큼 리모컨 을 사용할 수 있지만 "origin"이라는 리모컨은 하나만 가질 수 있습니다. "origin"이라는 원격은 기존 저장소를 복제 할 때 Git에 의해 작성된 기본 원격이라는 점을 제외하고는 특별한 방식이 아닙니다. 두 번째 리모컨을 구성하고 해당 리모컨에서 푸시 / 풀하고 원점 대신 해당 리모컨에서 분기를 추적하도록 일부 분기를 설정할 수 있습니다.

대신 "github"라는 원격 장치를 추가하십시오.

$ git remote add github https://github.com/Company_Name/repository_name.git

# push master to github
$ git push github master

# Push my-branch to github and set it to track github/my-branch
$ git push -u github my-branch

# Make some existing branch track github instead of origin
$ git branch --set-upstream other-branch github/other-branch

나중에이 질문에 걸림돌이되는 사람을위한 참고로 한 번에 둘 이상의 git 리포지토리 서버로 원점을 푸시 할 수 있습니다.

다음 명령을 사용하여 다른 URL을 오리진 리모트에 추가하여이를 달성 할 수 있습니다.

git remote set-url --add origin ssh://git@bitbucket.org/user/myproject.git

다음은 GitHub & GitLab에 여러 리모컨이 포함 된 샘플 프로젝트입니다.

  1. GitHub에 대한 원격 저장소 추가

    $ git remote add github https://github.com/Company_Name/repository_name.git
    
  2. GitLab에 대한 원격 저장소 추가

    $ git remote add gitlab https://gitlab.com/Company_Name/repository_name.git
    
  3. 이제 프로젝트에 여러 리모컨이 있습니다. 로 다시 확인git remote -v

    $ git remote -v
    github https://github.com/Company_Name/repository_name.git (fetch)
    github https://github.com/Company_Name/repository_name.git (push)
    gitlab https://gitlab.com/Company_Name/repository_name.git (fetch)
    gitlab https://gitlab.com/Company_Name/repository_name.git (push)
    
  4. 여러 저장소로 어떻게 푸시합니까?

    $ git push github && git push gitlab
    

원본 대신 다른 이름을 지정하여 저장소에 다른 원격 계정을 추가 할 수 있습니다. origin2와 같은 이름을 사용할 수 있습니다. 따라서 git 명령을 다음과 같이 수정할 수 있습니다

git remote add origin2 https://github.com/Company_Name/repository_name.git

git remote add origin2 https://github.com/Company_Name/repository_name.git

푸시 용 :

git push -u origin2 master

참고 URL : https://stackoverflow.com/questions/11690709/can-a-project-have-multiple-origins

반응형