Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Marking a repo as a fork in github, after the fact

Tags:

git

github

We have a project that was forked a while back mostly via a copy/paste method. But there is still significant overlap between the repos.

Is it possible to retroactively mark this fork as a fork to github, so that functions like compare and pull requests will do the right thing?

Note: I have tried the "hack" below, of forking anew, cloning the fork, copying the "forked" content over, then git add/commit/push. However, the file histories in the original "fork" are lost, and branches don't come over.

like image 207
karlos Avatar asked May 27 '15 03:05

karlos


People also ask

Can I fork into an existing repo?

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.

How do I fork an existing GitHub repository?

You can fork any repo by clicking the fork button in the upper right hand corner of a repo page. Click on the Fork button to fork any repo on github.com.

When should you fork a repository?

Most commonly, forks are used to either propose changes to someone else's project to which you do not have write access, or to use someone else's project as a starting point for your own idea. You can fork a repository to create a copy of the repository and make changes without affecting the upstream repository.


1 Answers

As you don't want to "squash" your commits into a single file what you could do is:

  • Fork the "original" repository
  • Create a pull request from your "copy and paste" repo to the fork

Or you could take a look at how to merge two repositories like in this post. Like they did there you could add your "c&p repo" to the fork as a subtree, like it is explained in detail over here.

This are the steps taken in the guide:

git remote add -f c&prepo /path/to/c&prepo git merge -s ours --no-commit c&prepo/master git read-tree --prefix=vendor/c&prepo/ -u c&prepo/master git commit 

However even with those methods you aren't able to merge the whole repositories but only specific branches. What you could do is i.e. create a pull request (described in my first method) for each branch, which could take up some time depending on your branching model.

I don't think there actually is a solution where you can merge two different repositories while keeping their commit history and branches at the same time. Best of luck to you.

like image 150
creyD Avatar answered Sep 18 '22 22:09

creyD