git 将 Gist 仓库转移到 github
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13671328/
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
Transfer gist repo to github
提问by Christopher Chiche
I am working on a small project with gist and since it is growing I would like to put it on github.
我正在开发一个带有 Gist 的小项目,由于它在不断发展,我想把它放在 github 上。
Let's suppose that:
让我们假设:
- my gist repo is at: https://gist.github.com/1234
- my new (empty) repo is at: https://github.com/ChrisJamesC/myNewProject
- 我的要点回购位于:https: //gist.github.com/1234
- 我的新(空)存储库位于:https: //github.com/ChrisJamesC/myNewProject
The ideal solution would be one that pushes my changes on both the gist and the github repository.
理想的解决方案是将我的更改同时推送到 gist 和 github 存储库。
采纳答案by Konrads
Github now has a new feature - import from another repository. So the steps are much simplified:
Github 现在有一个新功能——从另一个存储库导入。所以步骤大大简化了:
- Use the import featureand specify the URL of the repository.
- Profit!
- 使用导入功能并指定存储库的 URL。
- 利润!
Update:
更新:
You don't have to create a repo. The +button in the top right corner now has 'Import Repository' as an option.
您不必创建回购。右上角的+按钮现在有“导入存储库”作为选项。
回答by gzm0
You can add the github repository as a remote to your checked out gist repository.
您可以将 github 存储库作为远程添加到您检出的 gist 存储库。
git clone [email protected]:1234.git
git remote add github [email protected]:ChrisJamesC/myNewProject.git
Push it to initialize the git on github
推送到github上初始化git
git push -u github master
If your github repo wasn't quiteempty (you created it with a README, license, etc. which you don't mind losing) you will have to do a force overwrite on your push
git push -f -u github master
If you don't want to lose the exiting commits and files, see https://stackoverflow.com/a/40408059/117471
如果您的 github 存储库不是很空(您使用自述文件、许可证等创建它,但您不介意丢失),您将不得不对推送进行强制覆盖
git push -f -u github master
如果您不想丢失现有的提交和文件,请参阅https://stackoverflow.com/a/40408059/117471
This will also change the upstream of the branch, so github will be default.
这也会改变分支的上游,所以 github 将是默认的。
You now can rename the remote of gist:
您现在可以重命名 gist 的远程:
git remote rename origin gist
Each time you make changes (or pull changes from github/gist), you can do:
每次进行更改(或从 github/gist 拉取更改)时,您可以执行以下操作:
git push # To github
git push gist master # To gist
This will also push back your changes to the gist and not only the github repo.
这也会将您的更改推回到要点,而不仅仅是 github 存储库。
回答by bpj
Sorry for shaking an old question, and that I can't comment, but in the second step as given by gzm0 you may have to use --force, i.e.
很抱歉动摇了一个老问题,我无法发表评论,但在 gzm0 给出的第二步中,您可能必须使用 --force,即
git push -f -u github master
It may have been because there was a README in the Github repo, but I guess others may run into this too.
可能是因为 Github 存储库中有一个 README,但我想其他人也可能会遇到这个问题。
回答by knittl
Clone the gist (e.g. git clone git://gist.github.com/123.git
) to your local harddrive, then set the new URL for origin
(e.g. git remote set-url origin https://github.com/ChrisJamesC/myNewProject
). Push to the new repository (git push origin master
). Happy gitting!
将要点(例如git clone git://gist.github.com/123.git
)克隆到本地硬盘,然后为origin
(例如git remote set-url origin https://github.com/ChrisJamesC/myNewProject
)设置新 URL 。推送到新存储库 ( git push origin master
)。快乐的吉丁!
回答by rubo77
You can clone the gist locally.
您可以在本地克隆要点。
Add the github repository as new remote.
将 github 存储库添加为新的远程。
Push your local repository to the new github remote.
将您的本地存储库推送到新的 github 远程。
Delete all files in your gist but the README.md file . in this file you can write a hint that the gist has moved to a new repository
删除 gist 中的所有文件,但 README.md 文件。在这个文件中,你可以写一个提示,说明要点已经移动到一个新的存储库
回答by Bruno Bronosky
My edit to the accepted answer was getting lengthy so I created a separate answer to hold it.
我对已接受答案的编辑变得冗长,因此我创建了一个单独的答案来保留它。
If your repo is not empty and you don't want to lose the exiting commits and files, the accepted answerdoesn't apply to you.You will have to either:
如果您的 repo 不为空并且您不想丢失现有的提交和文件,则接受的答案不适用于您。您必须:
- If you do not care about the commit history of the gist...
- Copy the files over,
git add
,git commit
- Copy the files over,
- If you want to keep the commit history of the gist...
- Use git
cherry-pick
orformat-patch
which is outside of the scope of this answer. See Is it possible to cherry-pick a commit from another git repository?
- Use git
- 如果您不关心要点的提交历史...
- 复制文件,
git add
,git commit
- 复制文件,
- 如果您想保留要点的提交历史...
- 使用 git
cherry-pick
或format-patch
不在本答案范围内的。请参阅是否可以从另一个 git 存储库中挑选提交?
- 使用 git