我分叉了一个项目,进行了更改,并创建了一个被接受的拉取请求。新的提交后来被添加到存储库中。我怎样才能把这些承诺交给我?


当前回答

我用这一行更新我的分叉回购:

git pull https://github.com/forkuser/forkedrepo.git branch

如果您不想在项目中添加另一个远程端点,请使用此选项,如其他解决方案所示。

其他回答

Android Studio现在已经学会了使用GitHub fork存储库(您甚至不必通过控制台命令添加“上游”远程存储库)。

打开菜单VCS→ Git公司

并注意最后两个弹出菜单项:

重新使用我的GitHub分叉创建拉取请求

试试看。我使用第一个来同步本地存储库。无论如何,在您单击“Rebase my GitHub fork”后,可以在Android Studio中访问父远程存储库(“上游”)的分支,您将能够轻松地使用它们进行操作。

(我使用带有“Git集成”和“GitHub”插件的Android Studio 3.0。)

如何在本地计算机上更新分叉回购?

首先,检查遥控器/主机

git remote -v

你应该有起点和上游。例如:

origin  https://github.com/your___name/kredis.git (fetch)
origin  https://github.com/your___name/kredis.git (push)
upstream    https://github.com/rails/kredis.git (fetch)
upstream    https://github.com/rails/kredis.git (push)

之后转到main:

git checkout main

并从上游合并到干管:

git merge upstream/main

尝试此操作,单击“获取上游”以从上游主机同步分叉的回购。

在分叉存储库的本地克隆中,可以将原始GitHub存储库添加为“远程”。(“Remotes”就像是存储库URL的昵称,例如,origin就是其中之一。)然后,您可以从上游存储库中获取所有分支,并重新设置工作基础,继续使用上游版本。就命令而言,可能如下所示:

# Add the remote, call it "upstream":

git remote add upstream https://github.com/whoever/whatever.git

# Fetch all the branches of that remote into remote-tracking branches

git fetch upstream

# Make sure that you're on your master branch:

git checkout master

# Rewrite your master branch so that any commits of yours that
# aren't already in upstream/master are replayed on top of that
# other branch:

git rebase upstream/master

如果您不想重写主分支的历史记录(例如,因为其他人可能已经克隆了它),那么应该用gitmergeupstream/master替换最后一个命令。然而,为了做出尽可能干净的进一步拉取请求,可能最好重新设置基址。


如果您已经将分支重新基于upstream/master,则可能需要强制推送,以便将其推送到GitHub上自己的分叉存储库。你可以这样做:

git push -f origin master

您只需要在重新启动后第一次使用-f即可。

从github页面删除远程设备

然后应用这些命令:

1) git branch -D dev
2) git fetch upstream
3) git checkout master
4) git fetch upstream && git fetch upstream --prune && git rebase upstream/master && git push -f origin master
5) git checkout -b dev
6) git push origin dev
7) git fetch upstream && git fetch upstream --prune && git rebase upstream/dev && 8) git push -f origin dev

要查看配置,请使用以下命令:

git remote -v