更新时间:2022-10-15 20:27:05
确保您已将上游分支拉入您的本地回购:
git fetch upstream
检索新的上游分支 创建并切换到新的上游分支的本地版本( newbranch
):
git checkout -b newbranch upstream / newbranch
当您准备将新分支推送到来源时:
git push -u origin newbranch
$ b
-u 开关设置对指定远程的跟踪(在本例中, origin
)
I have a fork (origin
) from a project (upstream
) on github. Now the upstream project has added a new branch, I want to import into my fork. How do I do that?
I tried checking out the remote and creating a branch on top of that, but that configures the branch the way that git push
is trying to push to the upstream
:
git checkout upstream/branch
git checkout -b branch
Maybe that wasn't clear, but I want to add the branch to my local repository, so I can push it to origin
(my fork) via git push
. Because upstream repositories are usually read-only and you fork it to contribute.
So I basically want to checkout a non-existent branch on origin
whose contents will be pulled in from upstream
.
Make sure you've pulled the new upstream branch into your local repo:
git fetch upstream
to retrieve the new upstream branchCreate and switch to a local version of the new upstream branch (newbranch
):
git checkout -b newbranch upstream/newbranch
When you're ready to push the new branch to origin:
git push -u origin newbranch
The -u switch sets up tracking to the specified remote (in this example, origin
)