[英]Not able to pull the code through git pull
我的远程 GitHub 存储库中有两个以下分支:
master
test-branch
我做了git pull
入我的测试目录,但我没有看到任何代码拉入我的本地目录。 此外,当我执行git branch
时,我在这里看不到任何本地分支列表。 不知道为什么? 但是一旦我执行git branch -a
,请参阅下面以红色显示的远程分支:
remotes/origin/master
remotes/origin/test-branch
当我执行特定的分支拉取,即git pull origin test-branch
时,我看到代码被拉到我的测试目录中,但是当我执行git branch
时,我看到以下列表:
* master
remotes/origin/test-branch [displayed in red]
当我提取测试分支代码时,不知道为什么它在这里显示 master 。 另外我怎么能看到这个master指向哪个远程分支?
当您执行git pull origin test-branch
时,它实际上会从origin
远程master
分支中提取更改并将它们合并到当前签出的分支中。
git fetch
git checkout --track origin/test-branch
这将基本上执行以下操作:
git fetch
将更新为远程test-branch
的本地分支origin/test-branch
设置为远程跟踪分支origin/test-branch
来自 git 手册:
-t, --track
When creating a new branch, set up "upstream" configuration. See "--track" in git-branch(1) for details.
If no -b option is given, the name of the new branch will be derived from the remote-tracking branch, by looking at the local part of the refspec configured for the corresponding remote, and then stripping the
initial part up to the "*". This would tell us to use hack as the local branch when branching off of origin/hack (or remotes/origin/hack, or even refs/remotes/origin/hack). If the given name has no slash, or the
above guessing results in an empty name, the guessing is aborted. You can explicitly give a name with -b in such a case.
所以这基本上意味着如果你的远程分支被称为origin/test-branch
它将调用你本地创建的分支test-branch
。
git status
如果它正在跟踪,将在第二行显示它正在跟踪的远程
git branch -vv
将向您显示本地分支机构的列表以及他们正在跟踪的远程
查看此stackoverflow 答案以获得更详细的答案。
默认情况下, git pull origin xyz
运行git fetch origin xyz
然后git merge FETCH_HEAD
。 需要注意的是,指定的远程分支并没有被检出,而是集成到本地分支中。
它显示* master
因为您实际上没有通过运行git pull origin xyz
切换到不同的分支。 但是,分支xyz
的更改已集成到您的本地master
分支中,因为在获取后执行了合并。 可能您想首先切换到所需的分支( git checkout xyz
)然后拉动更改( git pull
)。
您可以使用git branch -a -vv
显示远程和本地分支,包括跟踪信息以及当前签出的分支:
* xyz b7b2f7c [origin/xyz] Commit Message A
main 8c4124b [origin/main] Commit Message B
remotes/origin/HEAD -> origin/main
remotes/origin/xyz b7b2f7c Commit Message A
remotes/origin/main 8c4124b Commit Message B
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.