git 如何在不添加单独遥控器的情况下保持前叉同步?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20984802/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I keep my fork in sync without adding a separate remote?
提问by 1ace
Let's assume there is a repository someone/foobar
on GitHub, which I forked to me/foobar
.
假设someone/foobar
GitHub 上有一个存储库,我将其分叉到me/foobar
.
How do I pull new commitsfrom the parent repository directly to my fork, without having to add a separate remoteand remember to pull regularly from there?
如何将新提交从父存储库直接拉到我的分支,而不必添加单独的远程并记住从那里定期拉?
The goal is to:
目标是:
git pull
to fetch from the parent repositorygit push
to send everything to my fork
git pull
从父存储库中获取git push
将所有内容发送到我的叉子
采纳答案by 1ace
git remote set-url origin [email protected]:someone/foobar
git remote set-url origin --push [email protected]:me/foobar
There is one caveat though:
This is perfect if you are the only one making changes to your fork.
However, if it is shared with other people, you may have to pull from your fork, in which case a separate remoteis the only solution.
不过有一个警告:
如果您是唯一一个对前叉进行更改的人,那么这是完美的。
但是,如果它与其他人共享,您可能必须从叉子中拉出,在这种情况下,单独的遥控器是唯一的解决方案。
Edit:
Actually, you cangit pull [email protected]:me/foobar
, which removes the caveat.
The choice is yours as to which is easier to remember.
编辑:
实际上,你可以git pull [email protected]:me/foobar
,这消除了警告。
选择哪个更容易记住是您的选择。
回答by Olufemi Israel Olanipekun
Open the forked Git repository me/foobar.
打开分叉的 Git 存储库me/foobar。
Click on Compare:
点击比较:
You will get the notification:
您将收到通知:
There isn't anything to compare.
someone:masteris up to date with all commits from me:master. Try switching the basefor your comparison.
没有什么可以比较的。
有人:master是最新的所有来自me:master 的提交。尝试切换基准进行比较。
Click on switching the baseon this page:
在这个页面点击切换基地:
Then you get to see all the commits made to someone/foobarafter the day you forked it.
然后你可以看到在你分叉的那天之后对某人/foobar所做的所有提交。
Click on Create pull request:
单击创建拉取请求:
Give the pull request a title and maybe a description and click Create pull request.
为拉取请求指定标题和描述,然后单击创建拉取请求。
On the next page, scroll to the bottom of the page and click Merge pull requestand Confirm merge.
在下一页上,滚动到页面底部并单击Merge pull request和Confirm merge。
Your Git repository me/foobarwill be updated.
您的 Git 存储库me/foobar将被更新。
Edit: rebase options are shown here:
编辑:rebase 选项显示在此处:
回答by Nadir
I used a fairly simple method using the GitHub Web UIto do that:
我使用GitHub Web UI 使用了一个相当简单的方法来做到这一点:
- Open the original Git repository (not the forked Git repository
me/foobar
) - Jump to the src folder, and open the file you want to change
- Click the pen icon. It will automatically create a label in your personal fork named "patch-1" based on the current version of the master repository:
- Enjoy!
- 打开原始 Git 存储库(不是分叉的 Git 存储库
me/foobar
) - 跳转到src文件夹,打开你要修改的文件
- 单击笔图标。它将根据主存储库的当前版本在您的个人分支中自动创建一个名为“patch-1”的标签:
- 享受!
回答by krlmlr
The "Pull" appis an automatic set-up-and-forget solution. It will sync the default branch of your fork with the upstream repository.
的“拉”的应用程序是自动设置和忘记的解决方案。它会将您的 fork 的默认分支与上游存储库同步。
Visit the URL, click the green "Install" button and select the repositories where you want to enable automatic synchronization.
访问 URL,单击绿色的“安装”按钮并选择要启用自动同步的存储库。
The branch is updated once per hour directly on GitHub, on your local machine you need to pull the master branch to ensure that your local copy is in sync.
该分支每小时更新一次,直接在 GitHub 上,在您的本地机器上,您需要拉取 master 分支以确保您的本地副本同步。
Also answered in https://stackoverflow.com/a/58965171/946850.
回答by Steve Moser
回答by Thomas Guyot-Sionnest
I don't know how it can be done without adding another remote, however I always add the repo I forked from as the upstream
remote so I could simply do:
我不知道如何在不添加另一个遥控器的情况下完成它,但是我总是将我分叉的存储库添加为upstream
遥控器,因此我可以简单地执行以下操作:
git branch -a|grep remotes/upstream| while IFS="/" read p r b; do echo Syncing $r/$b to origin/$b; git push origin $r/$b:refs/heads/$b; done
This will sync all branches incl. creating new ones (remove the refs/heads/
to only update existing branches). If any of your branches has diverged it will throw an error for that branch.
这将同步所有分支,包括。创建新的(删除refs/heads/
只更新现有的分支)。如果您的任何分支发生分歧,它将为该分支引发错误。