如何将上游分支的更改合并到我的分支分支

std*_*err 11 git merge git-fetch

我想从上游存储库的分支中提取更改。我已经使用以下命令设置了上游存储库:

git remote add upstream http://URL-of-master-repo.git 
Run Code Online (Sandbox Code Playgroud)

然后我尝试使用来拉取更改

git checkout my-local-branch
git fetch upstream remote-branch
git merge upstream/remote-branch
Run Code Online (Sandbox Code Playgroud)

但文件仍然没有出现在我的磁盘上,但我遇到了冲突:

Auto-merging minimal-build-config.cmake
CONFLICT (content): Merge conflict in minimal-build-config.cmake
Automatic merge failed; fix conflicts and then commit the result.
Run Code Online (Sandbox Code Playgroud)

如何正确解决冲突以便能够从上游分支获取文件?

b-f*_*-fg 15

一个好的做法是采用这种结构,它看起来像您所做的那样,但为了澄清目的最好进行解释:

origin  https://github.com/your-username/forked-repository.git (fetch)
origin  https://github.com/your-username/forked-repository.git (push)
upstream    https://github.com/original-owner-username/original-repository.git (fetch)
upstream    https://github.com/original-owner-username/original-repository.git (push)
Run Code Online (Sandbox Code Playgroud)

origin您的分叉和upstream原始存储库也是如此。然后使用

git fetch upstream
Run Code Online (Sandbox Code Playgroud)

你会得到这个输出

From https://github.com/original-owner-username/original-repository
 * [new branch]      master     -> upstream/master
Run Code Online (Sandbox Code Playgroud)

现在您有一个名为的分支upstream/master,用于跟踪原始存储库。

然后签出到本地分支分支并合并

git checkout master
git merge upstream/master
Run Code Online (Sandbox Code Playgroud)

如果您有冲突(看起来确实如此),请修复它们并提交更改。

来源