-단일 분기 클론을 “실행 취소”하려면 어떻게합니까? <target directory> 이 브랜치 만 복제했지만 이제

나는 다음을 사용하여 저장소를 복제했습니다.

git clone -b <branch name> --single-branch <github url> <target directory>

이 브랜치 만 복제했지만 이제 마스터 및 다른 브랜치로 전환하고 싶습니다. –single-branch 기본 설정을 취소 할 수있는 나머지 리포지토리를 지우고 다시 시작하는 것 외에 다른 방법이 있습니까?



답변

Git에게 다음과 같이 모든 분기를 가져 오도록 지시 할 수 있습니다.

git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin

.git/config보면 다음과 같이 보일 것입니다.

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = false
[remote "origin"]
    url = https://github.com/owner/repo.git
    fetch = +refs/heads/master:refs/remotes/origin/master
[branch "master"]
    remote = origin
    merge = refs/heads/master
    rebase = true

나는 이것을 전체 클론과 비교했고 유일한 차이점은 [remote "origin"].

참고 : Git 버전 1.8.2를 실행하고 있습니다. 이전 버전의 Git을 실행중인 경우 구성 옵션이 변경되었을 수 있습니다. 내 명령이 작동하지 않으면 .git/config비슷한 것을 볼 수 있는지 살펴 보는 것이 좋습니다 .


답변

단일 분기를 추가하려는 경우 다음을 수행 할 수 있습니다.

git remote set-branches --add origin [remote-branch]
git fetch origin [remote-branch]:[local-branch]

git 버전 1.9.1에서 작동


답변

사용하여 복제 된 로컬 저장소 에 다른 원격 분기를 추가하려면--single-branch 다음이 적합합니다.

git remote set-branches --add origin [remote-branch]
git fetch
git checkout [remote-branch]

[remote-branch]예를 들어 와일드 카드를 사용할 수도 있습니다.

git remote set-branches --add origin release-1.*
git fetch
git checkout release-1.5

이것은 git 버전 2.21.1을 사용하여 작동합니다 . git fetch origin [remote-branch]:[local-branch]추적되지 않은 상태에서 로컬 브랜치를 생성하기 때문에 권장 하지 않는 다른 답변 은 작동하지 않았습니다. 처음 실행할 때 git pull원격 브랜치의 모든 커밋을 로컬 브랜치에 다시 병합하려고했습니다.


답변

원래 repo를 새 리모컨으로 추가하고 거기서 작업 하시겠습니까?

git remote add path/to/myrepo myNewOrigin
git fetch myNewOrigin

현재 ‘origin’리모컨을 삭제하고 원하는 경우 ‘myNewOrigin’을 ‘origin’으로 이름을 바꿀 수도 있습니다.

거기에서 풀 / 병합 / 리베이스 할 수 있습니다.


답변

그냥 변경 .git/config지역의 repo의 파일 라인 fetch[remote origin] section.

이런 일 전에

[remote "origin"]
    url = https://github.com/owner/repo.git
    fetch = +refs/heads/master:refs/remotes/origin/master

그렇게 될 후에

[remote "origin"]
    url = https://github.com/owner/repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*


답변

나는 처음에 Dominik Pawlak의 답변을 적용했고 효과가있었습니다. 하지만 새 브랜치에 더 많은 코드를 커밋 한 후에는 더 이상 변경 사항을 가져올 수 없었습니다.

single-branch여기에 언급되지 않은 완전히 재설정하는 또 다른 방법이 있습니다.

git remote remove origin
git remote add origin git@gitlab.com:{yourProject}/{yourRepo}.git
git branch --set-upstream-to=origin/{yourBranch}  {yourBranch}
git pull

이렇게하면 모든 것이 원본으로 재설정됩니다.


답변

나를 위해 일했습니다.

git remote remove origin
git remote add origin https://*<yourPath>*.git
git fetch