추가 Git 리포지토리로 커밋 푸시 - AWS CodeCommit

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

추가 Git 리포지토리로 커밋 푸시

변경 내용을 두 개의 원격 리포지토리에 푸시하도록 로컬 리포지토리를 구성할 수 있습니다. 예를 들어, 사용자는 AWS CodeCommit을 사용해 보는 동안 기존 Git 리포지토리 솔루션을 계속 사용하려 할 수 있습니다. 다음 기본 단계에 따라 로컬 리포지토리의 변경 사항을 별도의 Git 리포지토리로 푸시하세요. CodeCommit

작은 정보

Git 리포지토리가 없는 경우 다른 CodeCommit 서비스에 빈 리포지토리를 만든 다음 CodeCommit 리포지토리를 해당 서비스로 마이그레이션할 수 있습니다. CodeCommit으로 마이그레이션의 단계와 유사한 단계를 따라야 합니다.

  1. 명령 프롬프트나 터미널에서, 로컬 리포지토리 디렉터리로 전환한 다음 git remote -v 명령을 실행합니다. 다음과 유사한 출력 화면이 표시되어야 합니다.

    HTTPS의 경우에는 다음과 같이 합니다.

    origin https://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo (fetch) origin https://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo (push)

    SSH의 경우에는 다음과 같이 합니다.

    origin ssh://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo (fetch) origin ssh://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo (push)
  2. git remote set-url --add --push origin git-repository-name명령을 실행합니다. 여기서 git-repository-name는 코드를 호스팅하려는 Git 리포지토리의 URL과 이름입니다. 이렇게 하면 origin의 푸시 대상이 해당 Git 리포지토리로 변경됩니다.

    참고

    git remote set-url --add --push은 푸시에 대한 기본 URL을 재정의하므로, 사용자는 이후 단계에서 설명하는 것처럼 이 명령을 두 번 실행해야 합니다.

    예를 들어 다음 명령은 원본 푸시를 일부 URL /로 변경합니다. MyDestinationRepo

    git remote set-url --add --push origin some-URL/MyDestinationRepo

    이 명령은 아무 것도 반환하지 않습니다.

    작은 정보

    보안 인증 정보가 필요한 Git 리포지토리로 푸시하는 경우에는 해당 보안 인증 정보를 보안 인증 도우미 또는 some-URL 문자열 구성에서 구성해야 합니다. 그러지 않으면 해당 리포지토리로의 푸시가 실패합니다.

  3. git remote -v 명령을 다시 실행하면 다음과 비슷한 출력이 생성됩니다.

    HTTPS의 경우에는 다음과 같이 합니다.

    origin https://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo (fetch) origin some-URL/MyDestinationRepo (push)

    SSH의 경우에는 다음과 같이 합니다.

    origin ssh://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo (fetch) origin some-URL/MyDestinationRepo (push)
  4. 이제 리포지토리를 추가합니다. CodeCommit 이번에는 리포지토리의 URL과 리포지토리 이름을 사용하여 git remote set-url --add --push origin CodeCommit 다시 실행합니다.

    예를 들어, 다음 명령은 https://git-codecommit.us-east-2.amazonaws.com/v1/repos/ 에 원본 푸시를 추가합니다MyDemoRepo.

    HTTPS의 경우에는 다음과 같이 합니다.

    git remote set-url --add --push origin https://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo

    SSH의 경우에는 다음과 같이 합니다.

    git remote set-url --add --push origin ssh://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo

    이 명령은 아무 것도 반환하지 않습니다.

  5. git remote -v 명령을 다시 실행하면 다음과 비슷한 출력이 생성됩니다.

    HTTPS의 경우에는 다음과 같이 합니다.

    origin https://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo (fetch) origin some-URL/MyDestinationRepo (push) origin https://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo (push)

    SSH의 경우에는 다음과 같이 합니다.

    origin ssh://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo (fetch) origin some-URL/MyDestinationRepo (push) origin ssh://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo (push)

    이제 푸시의 목적지로 두 개의 Git 리포지토리가 있지만 푸시는 먼저 some-URL/로 이동합니다. MyDestinationRepo 해당 리포지토리로의 푸시가 실패하면 커밋은 어느 리포지토리로도 푸시되지 않습니다.

    작은 정보

    다른 리포지토리에서 수동으로 입력해야 하는 자격 증명이 필요한 경우 먼저 푸시하도록 푸시 순서를 변경해 보세요. CodeCommit git remote set-url --delete를 실행하여 첫 번째로 푸시된 리포지토리를 삭제한 다음 git remote set-url --add를 실행하여 해당 리포지토리를 다시 추가합니다. 그러면 해당 리포지토리가 목록에서 두 번째 푸시 대상이 됩니다.

    다른 옵션들에 대해서는 Git 설명서를 참조하세요.

  6. 이제 두 원격 리포지토리로 푸시하고 있는지 확인하려면, 텍스트 편집기를 사용하여 로컬 리포지토리에 다음 텍스트 파일을 생성합니다.

    bees.txt ------- Bees are flying insects closely related to wasps and ants, and are known for their role in pollination and for producing honey and beeswax.
  7. git add를 실행하여 로컬 리포지토리에 변경 사항을 스테이징합니다.

    git add bees.txt
  8. git commit을 실행하여 로컬 리포지토리에 변경 사항을 커밋합니다.

    git commit -m "Added bees.txt"
  9. 커밋을 로컬 리포지토리에서 원격 리포지토리로 푸시하기 위해 git push -u remote-name branch-name을 실행합니다. 이때 remote-name은 로컬 리포지토리가 원격 리포지토리에 대해 사용하는 별명이고 branch-name은 리포지토리로 푸시할 브랜치의 이름입니다.

    작은 정보

    처음 푸시할 때만 -u 옵션을 사용하면 됩니다. 그러면 업스트림 추적 정보가 설정됩니다.

    예를 들어, git push -u origin main을 실행하면 푸시가 예상 브랜치의 두 원격 리포지토리로 이동한 것으로 표시되며, 출력은 다음과 유사합니다.

    HTTPS의 경우에는 다음과 같이 합니다.

    Counting objects: 5, done. Delta compression using up to 4 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 5.61 KiB | 0 bytes/s, done. Total 3 (delta 1), reused 0 (delta 0) To some-URL/MyDestinationRepo a5ba4ed..250f6c3 main -> main Counting objects: 5, done. Delta compression using up to 4 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 5.61 KiB | 0 bytes/s, done. Total 3 (delta 1), reused 0 (delta 0) remote: To https://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo a5ba4ed..250f6c3 main -> main

    SSH의 경우에는 다음과 같이 합니다.

    Counting objects: 5, done. Delta compression using up to 4 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 5.61 KiB | 0 bytes/s, done. Total 3 (delta 1), reused 0 (delta 0) To some-URL/MyDestinationRepo a5ba4ed..250f6c3 main -> main Counting objects: 5, done. Delta compression using up to 4 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 5.61 KiB | 0 bytes/s, done. Total 3 (delta 1), reused 0 (delta 0) remote: To ssh://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo a5ba4ed..250f6c3 main -> main

다른 옵션들에 대해서는 Git 설명서를 참조하세요.