Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the fork that a repository is linked to

Tags:

git

github

I have a repo called at MAIN/repo.git and I've forked it to FORK/repo.git. I have both of these repos cloned onto my computer for different purposes.

Using Github for Windows, a bug seems to have switched FORK/repo.git over to MAIN/repo.git, as when I do git remote show origin, the Fetch URL and Push URL are set to the main repo. How can I switch this back so the corresponding folder on my local machine points to FORK/repo.git, instead of MAIN/repo.git?

like image 431
zebra Avatar asked Jul 23 '12 19:07

zebra


People also ask

How do I change my forked repository?

To sync your forked repo with the parent or central repo on GitHub you: Create a pull request on GitHub.com to update your fork of the repository from the original repository, and. Run the git pull command in the terminal to update your local clone.

Can a forked repo be renamed?

Previously, when you forked a repository the fork name would default to the same name as the parent repository. In some cases, that wasn't ideal because you wanted the fork to have a different name. Your only option was to rename the fork after it was created.

How do I edit a GitHub fork?

Access your forked repository on Github. Click “Pull Requests” on the right, then click the “New Pull Request” button. Github first compares the base fork with yours, and will find nothing if you made no changes, so, click “switching the base”, which will change your fork to the base, and the original to the head fork.


1 Answers

The easiest way would be using command-line git remote, from within your local clone of FORK:

git remote rm origin git remote add origin https://github.com/user/FORK.git 

Or, in one command, as illustrated in this GitHub article:

git remote set-url origin https://github.com/user/FORK.git 

A better practice is to:

  • keep a remote referencing the original repo
  • make your work in new branches (which will have upstream branches tracking your fork)

So:

git remote rename origin upstream git branch -avv # existing branches like master are linked to upstream/xxx  git remote add origin https://github.com/user/FORK.git git checkout -b newFeatureBranch 

Whenever you need to update your fork based on the recent evolution of the original repo:

git checkout master git pull # it pulls from upstream! git checkout newFeatureBranch git rebase master # safe if you are alone working on that branch git push --force # ditto. It pushes to origin, which is your fork. 
like image 117
VonC Avatar answered Oct 06 '22 10:10

VonC