gpt4 book ai didi

git - 如何从远程存储库正确 check out 分支

转载 作者:行者123 更新时间:2023-12-05 08:24:13 26 4
gpt4 key购买 nike

我有这个

    abc@abc-ubuntu:~/project1/wh-app-ios$ git branch -a -v -v
* master 1d35af1 [origin/master: ahead 2] Adding 123 to hello
remotes/gitb/gh-pages e3dad9d boom
remotes/gitb/integration 1d3fcd5 Adding 55_Glossary chapter
remotes/gitb/master 86d1d30 Merge remote-tracking branch 'origin/master'
remotes/gitb/pt_BR dc9d991 Revisions at 03, 07, 08, 09, 10, 11 and 50
remotes/origin/HEAD -> origin/master
remotes/origin/master 1ae426b Update README.md

我愿意

    abc@abc-ubuntu:~/project1/wh-app-ios$ git checkout gitb/master
Note: checking out 'gitb/master'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

git checkout -b new_branch_name

HEAD is now at 86d1d30... Merge remote-tracking branch 'origin/master'

然后看看上面的警告信息我做

    abc@abc-ubuntu:~/project1/wh-app-ios$ git checkout -b mastergitb
Switched to a new branch 'mastergitb'

现在我在

    abc@abc-ubuntu:~/project1/wh-app-ios$ git branch -a -v -v
master 1d35af1 [origin/master: ahead 2] Adding 123 to hello
* mastergitb 86d1d30 Merge remote-tracking branch 'origin/master'
remotes/gitb/gh-pages e3dad9d boom
remotes/gitb/integration 1d3fcd5 Adding 55_Glossary chapter
remotes/gitb/master 86d1d30 Merge remote-tracking branch 'origin/master'
remotes/gitb/pt_BR dc9d991 Revisions at 03, 07, 08, 09, 10, 11 and 50
remotes/origin/HEAD -> origin/master
remotes/origin/master 1ae426b Update README.md
abc@abc-ubuntu:~/project1/wh-app-ios$

问题:

  1. 但显然 mastergitb 没有跟踪 gitb/master。这是为什么?

  2. 我是否只是创建了一个名为 mastergitb 的本地分支,它只是 gitb/master 的一个副本,但与它没有其他关系?

最佳答案

我不确定为什么消息没有提到这个,但你可以写

git checkout -t origin/branchname

创建一个名为branchname 的本地分支跟踪 origin/branchname ( -t--track 的缩写)。或者你可以写

git checkout -b localname -t origin/branchname

创建一个名为localname 的本地分支跟踪origin/branchname ,所以在你的例子中:

git checkout -b mastergitb -t gitb/master

是的,创建一个非跟踪分支正是您所做的。您可以通过删除分支并按照这些说明进行修复,或者通过运行 git branch --set-upstream mastergitb gitb/master 来修复它。为现有分支设置上游。

关于git - 如何从远程存储库正确 check out 分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18555072/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com