development

자식에서 다른 분기로 전환하려면 어떻게해야합니까?

big-blog 2020. 6. 19. 07:47
반응형

자식에서 다른 분기로 전환하려면 어떻게해야합니까?


이 줄 중 어느 것이 맞습니까?

git checkout 'another_branch'

또는

git checkout origin 'another_branch'

또는

git checkout origin/'another_branch'

그리고이 선들 사이의 차이점은 무엇입니까?



경우 another_branch이미 로컬에 존재하고이 지점에없는, 다음 git checkout another_branch분기로 전환됩니다.

경우 another_branch존재하지 않지만 origin/another_branch않습니다, 다음 git checkout another_branch에 해당합니다 git checkout -b another_branch origin/another_branch; git branch -u origin/another_branch. 의 업스트림으로 생성 another_branch하여 origin/another_branch설정 origin/another_branch합니다 another_branch.

둘 다 존재하지 않으면 git checkout another_branch오류를 반환합니다.

git checkout origin another_branch대부분의 경우 오류를 반환합니다. 경우 origin개정하고 another_branch다음 그 개정의 파일을 체크 아웃하지만 아마 대부분의 당신이 기대하지 어떤 것을하는 파일입니다. origin대부분에 사용되는 git fetch, git pull그리고 git push원격, 원격 저장소의 URL의 별칭으로.

git checkout origin/another_branchorigin/another_branch존재 하면 성공 합니다. 분기가 아닌 분리 된 HEAD 상태가됩니다. 새 커밋을 수행하면 기존 브랜치에서 새 커밋에 도달 할 수 없으며 브랜치 중 어느 것도 업데이트되지 않습니다.

업데이트 :

2.23.0이 릴리스되었으므로 git switch분기를 작성하고 전환하는 데 사용할 수도 있습니다 .

foo존재하는 경우 다음 으로 전환하십시오 foo.

git switch foo

foo존재하지 않는 경우 origin/foo작성 foo하여 origin/foo다음으로 전환하십시오 foo.

git switch -c foo origin/foo
# or simply
git switch foo

더 일반적으로 foo존재하지 않는 경우 foo알려진 참조 또는 커밋에서 생성 한 후 다음으로 전환하십시오 foo.

git switch -c foo <ref>
git switch -c foo <commit>

우리가 같은 시간에 Gitlab과 Github에서의 저장소를 유지하는 경우, 로컬 저장소는 예를 들어 두 개의 리모컨,있을 수 있습니다 originGitlab과 githubGithub에서를 들어. 이 경우 리포지토리에는 origin/foo및이 github/foo있습니다. git switch foo불평 fatal: invalid reference: foo이 심판,있는 알려져 있지 않기 때문에, origin/foo또는 github/foo만들 foo. 필요에 따라 git switch -c foo origin/foo또는 git switch -c foo github/foo필요에 따라 지정 해야합니다. 두 원격 지사 모두에서 지사를 만들려면 새 지사에 고유 한 이름을 사용하는 것이 좋습니다.

git switch -c gitlab_foo origin/foo
git switch -c github_foo github/foo

foo존재하는 경우 알려진 참조 또는 커밋 foo에서 다시 작성 / 강제 작성 (또는 재설정 foo) 한 후 다음으로 전환하십시오 foo.

git switch -C foo <ref>
git switch -C foo <commit>

이는 다음과 같습니다.

git switch foo
git reset [<ref>|<commit>] --hard

알려진 심판 또는 커밋의 분리 된 HEAD로 전환하십시오.

git switch -d <ref>
git switch -d <commit>

분기를 만들고 싶지만 전환하지 않으려면 git branch대신 사용하십시오. 알려진 심판 또는 커밋에서 브랜치를 생성하십시오.

git branch foo <ref>
git branch foo <commit>

자식에서 다른 지점으로 전환. 간단한 대답,

git-checkout-분기 전환 또는 작업 트리 파일 복원

git fetch origin         <----this will fetch the branch
git checkout branch_name <--- Switching the branch

브랜치를 전환하기 전에 수정 된 파일이 없는지 확인하십시오.이 경우 변경 사항을 커밋하거나 숨길 수 있습니다.


[ git checkout "branch_name"]

말하는 또 다른 방법입니다.

[ git checkout -b branch_name origin/branch_name]

"branch_name"이 원격으로 존재하는 경우

[ git checkout -b branch_name origin/branch_name]는 리모컨이 여러 개인 경우에 유용합니다.

[ git checkout origin 'another_branch']에 대해서는 이것이 확실하지 않습니다. AFAK "fetch"명령을 사용하여이 작업을 수행 할 수 있습니다-[ git fetch origin 'another_branch']


확인 : git branch -a

지점이 하나만있는 경우 그런 다음 아래 단계를 수행하십시오.

  • 1 단계 : git config --list
  • 2 단계 : git config --unset remote.origin.fetch
  • 3 단계 : git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/*

If you want the branch to track the remote branch, which is very import if you're going to commit changes to the branch and pull changes etc, you need to use add a -t for the actual checkout e.g.: git checkout -t branchname


With Git 2.23 onwards, one can use git switch <branch name> to switch branches.


What worked for me is the following:

Switch to the needed branch:

git checkout -b BranchName

And then I pulled the "master" by:

git pull origin master

참고URL : https://stackoverflow.com/questions/47630950/how-can-i-switch-to-another-branch-in-git

반응형