Un-fork GitHub project into new GitHub project not associated with the original [duplicate] - github

How can I make GitHub forget or disassociate that my repo was originally a fork of another project?
I forked a project in GitHub. I can now see "forked from whatever/whatever". The parent repository "whatever/whatever" is no longer maintained. I have been allowed to continue use of the code base of the original repository to create an independent repository.
Is there a way to detach my project from the original repository?

Update Jan 2022:
Use the GitHub chatbot-virtual-assistant at https://support.github.com/contact?tags=rr-forks&subject=Detach%20Fork&flow=detach_fork
First answer:
You can contact github support and ask them to switch your repository to "normal mode".
On this page, "Commit was made in a fork" paragraph, it is explained that one has to go through support to switch. Therefore, it is likely that there is no way to do that by yourself (unless you destroy and recreate your repo which is explained before... if you do so be careful if you have tickets or a wiki attached to your project as they will be deleted!).

You could duplicate the forked repository to a new repository (without the fork dependency) from the GitHub UI, then remove the original forked one:
Sign in to GitHub
Select the + sign in the top right corner and select Import repository.
Import your forked repository. The new repository won't have the fork dependency.
Delete the original, forked repository in the repository settings.
NOTE: This approach will not preserve issues and pull requests.

Make sure you have all the important branches and tags on your local repo, delete the github repo, recreate the repository through usual means (no forking) and push the local repository back with git push --all. Note that if you have local branches that you don't want to publish, might be worth to create a temporary clean local clone for the operation.
However, this will also get rid of wiki and issues. As the wiki is in fact it's own repository, it can be handled similarly by cloning it and then recreating and pushing. The repo address is on wiki's Git Access page (git#github.com:user/repo.wiki.git).
This leaves issues. They can be exported through the API, but as far as I know, you can only create issues and comments with your person, so importing them perfectly is impossible.
So, if you need issues to be preserved, you should go through github support as Thomas Moulard suggests.

I got the similar problem, and ended up using this github help page to solve it. I didn't mind about the wiki and issues tracker as it was for my blog using a theme kindly developed by another user.
To detach a forked repo and use it as your own after several commits without losing the whole history:
git clone --bare git#github.com:user/forked_repo.git
Create a new empty reposity new-repository on the github website.
And push a mirrored version:
cd user.github.com.git/
git push --mirror git#github.com:user/new-repository.git
One can rename on github, the forked_repository with another name to keep it as backup and check updates if needed. Or simply delete it.
Renaming the new-repository to the original name does the job. As a side effect, your commits now appear in your history.

Log in to GitHub with your credentials.
Go to https://support.github.com/contact?tags=rr-forks&subject=Detach%20Fork&flow=detach_fork.
Choose "Detach", then enter the URL or repo name of the fork as your-user-name/repository-name, and answer the other questions of the virtual assistant.
You will get an email with a ticket number where you can check the status of your request. You will also be notified per email once your repo has been deforked.
Most repository settings will stay unchanged, including user permissions, stargazers, issues, PRs, discussions, etc.

Using the info from aurelien and Clayton, I was able to do this with the following:
$ git clone --bare https://github.com/my/forked_repo.git
<delete forked_repo on GitHub>
<recreate repo on GitHub using same name>
$ cd forked_repo.git
$ git push --mirror
Here's the documentation for git clone --bare:
Make a bare Git repository. That is, instead of creating <directory> and placing the administrative files in <directory>/.git, make the <directory> itself the $GIT_DIR. This obviously implies the -n because there is nowhere to check out the working tree. Also the branch heads at the remote are copied directly to corresponding local branch heads, without mapping them to refs/remotes/origin/. When this option is used, neither remote-tracking branches nor the related configuration variables are created.
Here's the documentation for git push --mirror:
Instead of naming each ref to push, specifies that all refs under refs/ (which includes but is not limited to refs/heads/, refs/remotes/, and refs/tags/) be mirrored to the remote repository. Newly created local refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and deleted refs will be removed from the remote end. This is the default if the configuration option remote.<remote>.mirror is set.
Note: like the other git based answers, this will not copy over issues that are not part of the git repo such as the wiki and issues. Per Tapio:
The wiki is a separate git repo and can be handled in a similar fashion per Tapio. The address is: git#github.com:user/repo.wiki.git.
Issues can be exported via the GitHub API but there are issues recreating them since they can only be created by your user, so imports will lose information.

This only applies to GitHub Enterprise, not on github.com
Logged in to an account that has admin privileges:
Go to the repository that you need to detach: https://<ghe url>/<org>/<repo>
Click on the “Site Admin” rocket on the top right corner
Click "Collaboration" on the top menu bar
Click on “Network” on the left pane
Click on “Make Root” in the Network Structure pane
Accept
This was tested on GitHub Enterprise 2.9

If you do not need any past commits (I didn't in my case), you can just:
fork the project
make a local copy of the fork (I used my IDE to do that)
delete the git folder from your local copy
commit the project as you normally would a new project.
You can just delete the fork from your github account after. Took me all of one minute and worked like a charm.

Related

How to work on a project fork when having the original in Eclipse?

I'm trying to create a pull request on GitHub for project "original/QWERTY" so I forked the repo to "Mark/QWERTY". In Eclipse, I already have a repository set up for "original/QWERTY" and that project is in my workspace, named QWERTY.
Now if I create a new repository pointing at "Mark/QWERTY", I'll have two projects with the same name and both Eclipse and me won't like it.
I thought that it should be possible to have a branch or another remote under a repository and switch between them instead of having two copies (I mean just store the diffs). The problem is that they are different projects on GitHub so I'm not sure how to do it.
What is the correct way to set up two GitHub projects to create a pull request from my fork to the original one in Eclipse with EGit?
The usual workflow for forked repositories is to have a single local repository with a single work directory that is configured to fetch and push from/to multiple remote repositories.
With this setup, you can switch between branches that originate from different remote repositories.
The Fork a repo documentation of GitHub explains this setup when using CLI Git. Most of it should also apply to repositories hosted elsewhere.
Using the EGit documentation, it should be possible to translate these instructions into the corresponding actions in EGit.
How to manage multiple remotes with EGit is documented here: https://wiki.eclipse.org/EGit/User_Guide#Remote_Repositories
Using the information from Rudiger's comment and answer and my trial and error with branches I made my own steps. This picture also helps with terminology.
First, do these 2 things in any order:
fork the original project in the github website so now you have the original and the fork. They have the same code and branches.
create a local repository pointing to the original repo on github. Let's say you decided to select only the master branch.
Remotes: you get a new remote I'll call origin (default). configure its fetch if it's not done for you, the default specification is +refs/heads/*:refs/remotes/origin/*. This ref spec maps all the repo branches to Remote Tracking branches with the same name. If you want to only fetch the master branch then use +refs/heads/master:refs/remotes/origin/master.
Branches: you get a "Remote Tracking" branch called origin/master and a local branch called master with configuration of "Remote: origin" and "Upstream Branch: refs/heads/master". You will be working under the local master as it's the only branch right now.
Now you want to be able to push to your fork so you can create PR. You can and already did pull from the original to keep getting updates from other people's work.
Right click on "Remotes" and create a new remote, I'll call it fork (call it whatever you need). Configure its push.
the URI points to your fork the same way the origin Remote URI points to the original.
The ref mapping maps the branches. Go to "Advanced" and click "Add All Branch Specs" if it isn't done for you. You should get the spec refs/heads/*:refs/heads/*. It's easy to work with this spec but you can change it to whatever you need.
Create a local branch (right click -> switch to -> new branch) whose source is the local branch named master and the branch name is whatever suits what it does. it can be the master branch or a new branch that let's say fixes a bug, so bug 123. You do not have a Remote Tracking branch because those are used for pulls. If you also pull from fork then you will need to configure that in the Remote fork and get a remote branch.
Now you are working on a local branch bug 123 (you can see a checkmark next to it). Fix the bug in your code and in the Git Staging view you should see the files changed and the title is <Repository name> [bug 123]. Make sure you are going to commit/push to the correct branch! Stage whatever you need and commit (adds the changes to the local branch bug123) and push (creates a branch on the github repo called bug 123 if you stayed with the default spec).
Now go to the GitHub repo page of either the original or the fork and the UI will tell you that you can create a PR. From there GitHub will guide you.
Once the PR is merged into the master branch of the original on GitHubm, you will want to fetch from the master.
Right click on the Remote origin or its fetch "subdir" and choose fetch. The will fetch any changes in all the remote branches because the fetch spec we used maps all the branches (we used the * character).
That's it. Continue to switch to a local branch which maps to your fork based on the updated master, fix bug, commit and push, create PR, wait for merge into the original, fetch and pull from the original.

How can collaborators push their changes to my repo in GitHub

First I have created one project in Eclipse and committed to my GitHub using below commands:git init
git add .
git commit -m "first commit"
git remote add origin URI of my repo
git push -u origin master
Then I modified one file in Eclipse and committed to GitHub from Eclipse through creating remote and giving the remote URI of the repo.
I added my team member through add collaborator.
Then he downloaded my project and made a change in a file in Eclipse.
Now, how can he push that modified file to my GitHub repository from within Eclipse?
We have done one thing. He created a remote and gave the URI of my repo. But still we are unable to commit that file.
You need to add your colleague as a collaborator. This can be done in the desired GitHub repo via Settings > Collaborators (you need to type in your password again). Afterwards they have those permissions.
UPDATE
Sorry and good morning ;)
I overlooked that you already added your partner as a collaborator. Another possible reason for your situation could be in the Temporary interaction limits where you can, amongst others, limit the interaction with your repo to prior contributors.
If that doesn't help. Please add some more informations about your colleague's git logs.
UPDATE 2
#Rahul K regarding your comment (which you better add to your question, for faster recognition), your colleague first needs to integrate the remote changes via git pull origin master in order to be able to push his or her changes afterwards. But be aware that he or she might need to migrate any conflicts to files both of you applied changes to.
Best regards, David
I have resolved the issue by cloning the repo in my local folder, adding the project to eclipse and changing the file committed.
Before that you have to add that person as a collaborator. So that he/she can clone your repo using the command below:
git clone "Path to the repository"
This is an old question but I'll like to say this to help others that might still be facing this same issue.
I also faced this issue with a friend. I already made him a collaborator but he couldn't push. What we did to solve it was to clone the repo using the ssh url instead. Then we set up authentication in git with ssh. And we were able push successfully.
If you already cloned the repo with the usual HTTPS url, you can change the remote origin url using the git remote set-url origin <url> command but url here will be the ssh url.

How do you change the default base fork for a github pull request? [duplicate]

I have a set of documentation for my company's API, based on the excellent Slate framework from TripIt. Per instructions, I forked their repo and proceeded to customize it. That fork lives here.
The obnoxious thing is that when contributors in my organization do a new pull request, the "base fork" on the Github "Comparing Changes" screen defaults to TripIt's repository, not my fork. They've more than once sent pull requests to the wrong place. Telling people "don't do that" isn't a particularly reliable solution. How can I set the default for where PRs are based to my fork?
GitHub keeps track of forks made through their interface and assumes pull requests will be for that original repository. You need to tell GitHub that your copy is not a fork but rather a regular repository that just happens to have identical history. Sadly, GitHub doesn't offer a good way to just uncheck the fork link. I typically solve it this way:
Clone the repository, git pull, and ensure your local copy is completely up to date.
Delete the repository on GitHub.
Create the repository on GitHub using the exact same name. Ensure it's an empty repository (don't create a README or LICENSE file.)
git push all the content back into the repository. (You may need to switch to each branch and push it, and you also may need to git push --tags.)
FRAGILE: This approach will lose existing GitHub issues and pull request comments. If you're using these heavily, this approach is probably a bad idea, and you should contact GitHub customer support to help you instead.
It is unfortunate that GitHub does not provide a way to configure the default PR target repo.
If you can delete (or get the owner to delete) the original repo A from which B was forked, then that will do the trick.
If it is not possible/agreeable to delete A, but the owner of A is willing to do the following, then the fork link gets broken, on GitHub Enterprise at least:
mark repo A as Private
mark repo A as Public again
After doing this, repo B (which was originally forked from A) will default to opening PRs against itself, rather than A.
Note: if A itself was forked from something further back in the history, then unfortunately it seems that B starts defaulting to opening PRs against that repo once A has gone. The only solution would be to apply the above to all repos upstream in the fork tree :(
Your other developers seem to have forked TripIt's repository, so that is the source/parent of their work.
In fact, if you open your own repository, you will see it hasn't been forked at all (the fork count is 0).
When they issue a merge request, by default github shows that repository as source, and so the pull request isn't sent to you.
The simplest workaround in this case is to ask your dev's to fork your repository, and work on it.
Yes, it's a bad situation...
The only solution I know of (other than deleting the fork and recreating/pushing directly from a local clone as described here ) is to have the upstream owner make the original repo PRIVATE and then return it to PUBLIC. Taking it private breaks the link to forks permanently.
But of course that requires action by the upstream owner. Github should really solve this, but it's been an issue for a very long time.

Creating an official github mirror

How do I create a github mirror for an external git repository, such that it appears as "real mirror", e.g., as in https://github.com/mirrors?
So far, I set up a mirror using:
cd /path/to/bare/repository
git remote add --mirror github git#github.com:user/repo.git
and configure the post receive hook to do a git push --quiet github. This way, however, github does not recognize the mirror.
Any ideas how to do it the github way, such that "Mirrorred from" appears underneath the repostiory name?
Based on communicating with GitHub's support team, I found that GitHub currently offers no direct mechanism for a user to mirror repositories in this fashion.
However, one can ask GitHub to install this service for repositories which are part of an organization. GitHub then configures an existing repository as such a mirror and pulls from it in an interval that is a function of the number of overall mirrors they have.
EDIT: as Stuart points out, GitHub no longer accepts requests for mirroring arbitrary repositories. The only remaining option is the solution I posted in my question, i.e., creating a post-receive hook to automatically push to your GitHub repository.
Judging by the current content of https://github.com/mirrors, it would appear GitHub no longer does "official mirrors", as most projects that want their code mirrored on GitHub today just makea an organization for it, such as Git itself.
There is also a feature request at: https://github.com/isaacs/github/issues/415
According to Importing a Git:
For purposes of demonstration, we'll use:
An external account named extuser
A GitHub personal user account named ghuser
A GitHub repository named repo.git
The command line:
# Makes a bare clone of the external repository in a local directory
$ git clone --bare https://githost.org/extuser/repo.git
# Pushes the mirror to the new GitHub repository
$ cd *repo.git*
$ git push --mirror https://github.com/ghuser/repo.git
# Remove the temporary local repository.
$ cd ..
$ rm -rf repo.git
I have used a tool called github-backup with moderate success to, if not mirror, at least make a full backup (including issues and other metadata) of a Github user or organization. To quote the README file:
Each time you run github-backup, it will find any new forks on GitHub. It will add remotes to your repository for the forks, using names like github_torvalds_subsurface. It will fetch from every fork.
It downloads metadata from each fork. This is stored into a branch named "github". Each fork gets a directory in there, like torvalds_subsurface. Inside the directory there will be some files, like torvalds_subsurface/watchers. There may be further directories, like for comments: torvalds_subsurface/comments/1.
You can follow the commits to the github branch to see what information changed on GitHub over time.
The format of the files in the github branch is currently Haskell serialized data types. This is plain text, and readable, if you squint.
Limitations include:
no private repository support
no "social" stuff like stars, followers, etc
notes to lines of commits are not supported (yet?)
issue labels

Getting started with GitHub and Eclipse (spring source toolsuite 2.7.1)

I am new with both Git and GitHub so please bear with me.
I have an empty repository on GitHub with an automatically created branch (gh-pages), which, I understand, is supposed to be used with GitHub's pages functionality.
Now what I would like to do is to create and eclipse project from which I could commit/push to this repository.
What is confusing me that I can't see any option to create a remote branch on github. I suppose pushing my source to gh-pages won't be a good idea. BTW, I also don't understand why the GitHub pages is feature is implemented as a branch? Aren't branches supposed to be merged with each other at some point. Clearly it wouldn't make any sense to merge github pages into my project. Wouldn't it be better to have a folder within my project for this purpose.
I googled and found this link but being a git noob I am not sure if that's what I want to do. I would like to use Eclipse as my primary interface to git and github only falling back to command line or other interfaces when there is no other option.
OK I think I have figured it out. Basically, what you need is to define a remote ref that need not exist before hand.
Create a project
Team->Share it to a local repository
In the repository view (Window->Show View-> Git -> Repositories) select the local repository and right click on remotes
Select new remote (configure push). Type origin in the remote name. Press OK
Change URL. Copy/paste the ssh uri from github. Select ssh protocol (make sure you have ssh key defined in eclipse SSH preferences, and uploaded to github)
Now the last part is to add Ref mapping. Click on Add.. in ref mapping section of screen. And enter refs/heads/master in both local and remote branches.
Or may be the refs/heads/master on both side isn't a good idea :)
I see, cloning a github repo that doesn't have gh-pages branch is simpler as it automatically creates this remote fetch spec
Remote Fetch Specification +refs/heads/*:refs/remotes/origin/*
Maybe this is what I need to enter in the step 6 above
Ok as it turned out the original idea of "refs/heads/master in both local and remote branch" was correct. Pushing with this configuration is showing my changes in git hub correctly. The second option on the other hand is failing silently.
Branches typically are used in the way you described, but nothing says they must be used that way. This is just the way github chose to let you manage your page content, and it works quite well. It's kind of similar to hosting multiple repos on one SVN server.
As for creating new repos, if you create a repo in github and then clone it, you'll have an empty repo locally that already points to github with a remote named "origin". This is a convenient way to start out, since you don't have to mess with adding a remote yourself. At this point, your repo has no commits and no branches in it. When you make the first commit, it will automatically establish a branch named "master". I don't know how eclipse is set up by default, but from the command line with default settings, you have to explicitly push new branches to a remote or else they won't get pushed at all. I.e. making the first commit and doing git push will just fail with a message like "No refs in common and none specified; doing nothing". Instead, you have to git push origin master to tell it to establish the "master" branch in remote "origin" (aka github). Thereafter, just a git push will work fine.
Hope that clears up some of your confusion.