Copy/fork a git repo on github into same organization

守給你的承諾、 提交于 2019-11-28 16:55:55

问题


I have a repo on github that contains a web application that's deployed to two different domains. The application has slight logic forks here and there to behave differently depending on which domain it's deployed to.

It's come to the point to where I want to split it into two separate repos, one for each domain.

Github won't let me fork it into the same organization. Searching for "git duplicate repo" suggests I should bare clone and mirror push it, but that seems to be for keeping both repos in sync, which I don't want to do.

What's the best way to go about this? I'd like to preserve the old commit history in the new copy if possible.


回答1:


Just create a new repository and push to it from your working copy:

git clone git@github.com:me/myrepo-original
cd myrepo-original
git remote set-url origin git@github.com:me/myrepo-new
git push origin master

Now you have a new repository, myrepo-new, which is identical to myrepo-original.




回答2:


If you do not need the fork relation (e.g. you want some kind of decoupled alternate repo for whatever reason), duplicating the repo as outlines by your Google finds and larsks's answer is fine.

If you do want to make it a fork, contact Github support (support@github.com or https://github.com/support), and they will create a fork in the same organization for you. (They're not picky about this either, you'll have just to provide an alternative name for the repo, as repo names within an account must be unique.)


Update: User Steve Rice reports in the comments below that GitHub Support stated that support would not currently/no longer set up a second fork in your account. You can still try asking them, as support employees might be able to do it -- but this might also be a policy change preventing them from doing so.




回答3:


Use Github's Import Repository option on the + menu on top of the page

This creates a new repository with the exact contents of the copied repository. The downside is that it doesn't count as a fork for Github.




回答4:


Another way would be to add the original repo, to be copied, as remote for our current repo.

#create a new repo in the org1 organization called myrepo-new

In your local terminal, run:

git clone git@github.com:org1/myrepo-new
cd myrepo-new
git remote -v #shows current repo link on github as origin
git remote add name-for-remote https://github.com/org1/repo-old
git remote -v #shows repo-old as name-for-remote
git fetch  name-for-remote
git merge name-for-remote/branch-to-get-from-remote
#Now fix any conflicts if present
#If number of files/commits is very high, the desktop client may hang when you try to commit your changes after merge. Try switching to Git Shell if this happens.
git status 
git commit -m "commit message"
git push origin master



回答5:


Alternative solution:

Create a new organisation and fork it there. If the repo is private, it will stay private in the new org as well. Then you can give access to external devs or whoever you want to the forked repo and they can raise PRs back to original repo.




回答6:


Couldn't you just duplicate the local folder, delete the git stuff:

rm -rf .git*

Then make a new repository in that folder? Seems cleaner and easier.



来源:https://stackoverflow.com/questions/22767617/copy-fork-a-git-repo-on-github-into-same-organization

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!