Add Github fork to existing repository

2019-02-08 03:20发布

I setup an Octopress project following the given instructions (http://octopress.org/docs/setup/) which have you create a Github repository, and create a local repository on your machine. On your local machine you add a remote to the original Octopress repository and then issue a "git pull" command. Then you add a remote to your Github repository so you can push your changes to your repository.

All of this works as far as it goes, but it doesn't create a fork of the original project, meaning there's no obvious (to a newbie) way to issue a pull request to the original Octopress repository.

Is there a way for me to add a fork of the original Octopress repository to my instance of that repository on Github?

If there isn't a way, can I safely delete my Github instance of Octopress, fork the original on Github, and then add a new remote from my local repository to the newly forked Octopress?

标签: git github fork
3条回答
在下西门庆
2楼-- · 2019-02-08 03:26

I'm unaware of any way to turn your blank github copy into a github fork after the fact, so

If there isn't a way, can I safely delete my Github instance of Octopress, fork the original on Github, and then add a new remote from my local repository to the newly forked Octopress?

is the way to go. Delete your own github repository, hit the fork button on the octoprocess repository and clone your fork to your local machine.

If you've already made any changes that you with to keep, I'd say that using git format-patch to store them as a series of patch files and git apply-patch to apply those on a clone of your new repository is probably easier than using the old one as a remote (on your local machine).

查看更多
Animai°情兽
3楼-- · 2019-02-08 03:30

If I understand the OP. They have a Git repo, and they have now decided that it should have forked another repo. Retroactively they would like it to become a fork, without disrupting the team that uses the repo by needing them to target a new repo.

I've thought about renaming a new repo into place. so if the team current clones, and fetchs, and pulls example.git

  1. setup a new repo that is a fork, example_fork.git
  2. rename example.git to example_deprecated.git
  3. quickly rename example_fork.git to example.git.

I've heard that anyone who already had a clone would be met with an error of sorts (so that doesn't avoid the inconvenience as well as I would hope)

I've also seen suggestions to use Force Push: Marking a repo as a fork in github, after the fact

.

But now I'm wondering if topic of discussion is more accurately worded as "setting the upstream remote of an existing repository". Discussed here: Adding remote upstream to git repo on bit bucket

based on the feedback provided here: What does 'git remote add upstream' help achieve? I think it would basically allow retroactive forking like I want, and like I think the OP is asking for.

I have not tried it yet.

查看更多
看我几分像从前
4楼-- · 2019-02-08 03:34

Although people tend to think of their repo on Github as the "official" one, remember that's a social distinction and not a technical one. From git's point of view every repo is on equal terms. That means as long as you have pulled every commit into your local repo, you can safely delete the one on Github. Then just fork the Octopress project on github, set it up as a remote on your local repo, and push. Git doesn't care which repo you originally got any given commit from. It "just works."

查看更多
登录 后发表回答