简体   繁体   English

同步本地合并到远程 GitHub repo

[英]Sync local merge to remote GitHub repo

I created a test repo locally on my PC and added some text to it.我在我的 PC 上本地创建了一个测试存储库,并向其中添加了一些文本。 Then created a test branch, merged it with main, deleted the test branch and pushed everything with git push .然后创建一个测试分支,将其与 main 合并,删除测试分支并使用git push推送所有内容。 But when I check my GitHub copy of that repo the test branch still exists?但是当我检查我的 GitHub 副本时,测试分支仍然存在吗? Why?为什么?

deleted the test branch and pushed everything with git push.删除测试分支并使用 git push 推送所有内容。 But when I check my GitHub copy of that repo the test branch still exists?但是当我检查我的 GitHub 副本时,测试分支仍然存在吗? Why?为什么?

That is by design.这是设计使然。 If you delete a branch locally, this deletion will not be automatically propagated when pushing your repository to a remote repository.如果您在本地删除分支,则在将您的存储库推送到远程存储库时,此删除不会自动传播。 This is because in general, it is normal and expected for a remote repository to have (many) branches that you do not exist in your local repository.这是因为通常情况下,远程存储库具有(许多)您在本地存储库中不存在的分支是正常且预期的。

If you want to delete a branch in a remote repository, you need to delete it explicitly.如果要删除远程存储库中的分支,则需要显式删除它。 This is done with git push :这是通过git push完成的:

git push --delete origin name-of-branch-to-delete

where, "origin" is the name of the remote repository (which is "origin" by default), and name-of-branch-to-delete is, obviously, the name of the branch you want to delete.其中,“origin”是远程存储库的名称(默认为“origin”),而 name-of-branch-to-delete 显然是要删除的分支的名称。 Note that this must be the name of the branch in the remote repository - you may have given the branch a different name in your local repository (though by default the names will be the same).请注意,这必须是远程存储库中分支的名称 - 您可能在本地存储库中为分支指定了不同的名称(尽管默认情况下名称相同)。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM