[英]Do I need to git pull and merge to get the lastest update from a remote repository?
After I pushed my work to the feature branch of a remote repository, someone merged it to the main branch. 在将工作推送到远程存储库的功能分支之后,有人将其合并到主分支。
Since then, I haven't made any change to my local working directory and local repository and the remote repository, while others have made changes to the remote repository. 从那时起,我就没有对本地工作目录,本地存储库和远程存储库进行任何更改,而其他人则对远程存储库进行了更改。
Now I want to get the latest work from the remote repository, 现在,我想从远程存储库获取最新的工作,
git pull
the correct command? git pull
是正确的命令吗? Running git pull
doesn't succeed. 运行
git pull
不会成功。 The output of running git pull
contains the following 运行
git pull
的输出包含以下内容
There is no tracking information for the current branch.
当前分支没有跟踪信息。 Please specify which branch you want to merge with.
请指定您要合并的分支。 See git-pull(1) for details
详见git-pull(1)
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
如果您希望为此分支机构设置跟踪信息,可以使用以下方法:
git branch --set-upstream-to=origin/<branch> core-81
What does it mean? 这是什么意思?
Thanks. 谢谢。
You need to switch to the main branch by running 您需要通过运行切换到主分支
git checkout master
change master to your main branch (for example development
). 将master更改为您的主分支(例如
development
)。 Then run git pull
to get the latest work from the main branch. 然后运行
git pull
从主分支获取最新工作。
The most general usage of git pull
is git pull
的最一般用法是
git pull origin branch
Where origin
is the remote repository, and branch
is the remote branch to pull information from. 其中
origin
是远程存储库,而branch
是要从中提取信息的远程分支。 However, you can run 但是,您可以运行
git push -u origin branch
# or
git branch -u origin/branch branch
This command ( -u
stands for --set-upstream
) will set a remote branch as a tracking for this local branch and later on you will only need to run git pull
for this branch 此命令(
-u
代表--set-upstream
)将设置一个远程分支作为对此本地分支的跟踪,以后您只需要对该分支运行git pull
Description 描述
Besically, if you haven't set up upstream for your branch - it will fail to pull
; 基本上,如果您尚未为分支机构设置上游 -它将无法
pull
; simply because git
has no idea where to pull from 只是因为
git
不知道从哪里提取
In order to pull branch you are interested in you can run 为了拉你感兴趣的分支可以运行
git pull <remote> <branch>
Note: you can add -u
here to set up upstream at this point 注意:您可以在此处添加
-u
来进行上游设置
as git
is suggesting to you in the output provided. 正如
git
在提供的输出中建议您的那样。
git branch --set-upstream-to <branch> <remote>/<branch>
This instruction will manually set up upstream for specified branch as in the above signature. 该指令将按照上面的签名为指定的分支手动设置上游 。
You can also set this up automatically when pushing by doing 您也可以在进行推送时自动设置
git push -u <remote> <branch>
Note: -u
sets up an upstream 注意:
-u
设置上游
EDIT 1 编辑1
@torek @torek
While git pull has a -u option, it simply passes it on to git fetch, where it means --update-head-ok.
虽然git pull具有-u选项,但它只是将其传递给git fetch,这意味着--update-head-ok。 As the documentation says, "unless you are implementing your own Porcelain you are not supposed to use it."
正如文档所述,“除非您实施自己的瓷器,否则不应使用它。” Note that this is quite different from git push -u, which you are supposed to use as needed.
请注意,这与git push -u有很大不同,您应该根据需要使用它。
Reference 参考
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.