我正在使用gist工作小项目,由于它的规模不断扩大,我希望将它放到GitHub上。
假设:
- 我的gist repo位于:https://gist.github.com/1234
- 我的新(空)repo位于:https://github.com/ChrisJamesC/myNewProject
最理想的解决方案是将我的更改推送到gist和GitHub存储库中。
我正在使用gist工作小项目,由于它的规模不断扩大,我希望将它放到GitHub上。
假设:
最理想的解决方案是将我的更改推送到gist和GitHub存储库中。
git clone git@gist.github.com:1234.git
git remote add github git@github.com:ChrisJamesC/myNewProject.git
将其推送以在 GitHub 上初始化 git
git push -u github master
如果您的 GitHub 存储库不是完全空的(例如,您创建了一个自述文件、许可证等,而您不介意失去这些),则必须在推送时进行强制覆盖
git push -f -u github master
如果您不想丢失现有的提交记录和文件,请参阅https://dev59.com/5WYr5IYBdhLWcg3wcJx0#40408059。git remote rename origin gist
每当您进行更改(或从 GitHub / gist 拉取更改)时,您可以执行以下操作:git push # To github
git push gist master # To gist
这也会将您所做的更改推送回gist,而不仅仅是github仓库。
将这个Gist克隆到本地硬盘(例如git clone git://gist.github.com/123.git
),然后设置origin
的新URL(例如git remote set-url origin https://github.com/ChrisJamesC/myNewProject
)。 将更改推送到新仓库(git push origin master
)。祝你使用Git愉快!
很抱歉搬起了一个老问题,而且我无法评论,不过按照gzm0提供的第二步可能需要使用--force参数,即:
git push -f -u github master
可能是因为Github仓库中有README文件,但我猜其他人也会遇到这个问题。
--force
是非常危险的,因为它会覆盖存储库。也许最好创建另一个新的存储库,而不包括 README(无论如何都会消失)。请参阅 --force considered harmful; understanding git's --force-with-lease - Atlassian Developers。 - nealmcb我的编辑对已接受的答案变得很冗长,所以我创建了一个单独的答案来保留它。
如果您的存储库不为空并且不想丢失现有的提交和文件,则 已接受的答案 不适用于您。 您将不得不执行以下操作之一:
git add
,git commit
cherry-pick
或 format-patch
,这超出了本答案的范围。请参见是否可以从另一个git存储库中挑选提交?
git clone git@gist.github.com:1234.git
。 - Noah Sussmangit clone
命令来克隆gist时,我收到了一些错误信息。我怀疑解决办法可能是使用GitHub CLI和类似gh gist clone <gist>
的命令。 - EJ Mak