简体   繁体   English

是否需要git pull和merge才能从远程存储库获取最新更新?

[英]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, 现在,我想从远程存储库获取最新的工作,

  • is git pull the correct command? git pull是正确的命令吗?
  • will I not need to merge, because my last commit is an ancestor of the current commit on the main branch? 我不需要合并,因为我的最后一次提交是主分支上当前提交的祖先?

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 参考

6089294 6089294

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Git Lab 从 origin master 拉取 -(远程存储库),我如何解决合并冲突? - Git Lab pull from origin master - (remote repository), how do i resolve Merge Conflicts? 在合并之前,是否需要签出并拉出远程git分支? - Do I need to checkout and pull a remote git branch before I merge it in? 我怎么从远程跟踪分支''git fetch'和'git merge'(比如'git pull') - How Do I 'git fetch' and 'git merge' from a Remote Tracking Branch (like 'git pull') 我正在尝试从git获取最新代码时在git中拉出时间错误 - pull time error in git whil i am trying to get lastest code from git 当我执行git push / git pull时,是否有可能让git自动更新远程服务器上的注释 - Is it possible to get git to automatically update notes on the remote server when I do a git push/git pull 在 Git 中进行“拉动”之前是否需要“远程更新” - Do you need a 'remote update' before doing a 'pull' in Git 我如何从远程 git 中提取? - How do I pull from remote git? 如何从远程存储库合并/拉取 - How to merge/pull from remote repository git从远程存储库中提取所有分支 - git pull all branches from remote repository 无法从 Sourcetree 拉取 Git 远程存储库 - cannot pull Git remote repository from Sourcetree
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM