我经常遇到以下问题:
一种解决方案是:
git clone
步骤创建的新目录这似乎是一个很常见的解决方案,但据我所知,没有方便的解决方案。
如何将分支主控上的工作从本地存储库推送到远程?
如何将远程仓库中的新文件拉取到本地?
本质上,我想同步 2 个存储库,而不需要经历如上所述的创建新文件夹和删除旧文件夹的整个过程。我该怎么做?
当您在 GitHub 上创建新存储库时,它会准确告诉您需要执行哪些操作才能从现有本地存储库使用它。这是直接来自 GitHub 的:
...或从命令行推送现有存储库
git remote add origin https://github.com/YOURNAME/REPONAME.git git push -u origin master
仅此而已。
可以使用belo方式同步本地仓库和远程仓库(假设将所有文件保留在
master
分支中):
# In your local remote
git remote add origin <github repoURL> -f
git checkout origin/master .
git commit -m 'keep remote files with local files together'
git push -u origin master -f
现在 github 仓库
master
分支包含本地仓库和原始 github 仓库中的文件。