Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

forgot to do a fork on GitHub before starting my work

Tags:

github

Suppose I clone Company C's repo of Project X from github to my local machine. I create a branch for myself locally, do some work on it and make commits to my branch locally.

Now I want to make a pull request to Company C, but I realize that I should have done a fork on gitub to create my own repo of Project X and cloned that instead of Company C's repo.

How do I recover from this without cloning my fork locally and starting over by copying files manually? I'd like to use git's magic to save myself.

like image 482
JoelFan Avatar asked Mar 08 '15 15:03

JoelFan


People also ask

Can I contribute without forking?

You need to create a fork for every repository you contribute to... but creating branches in your fork allows you to work one more than one PR at once for the upstream repo. You don't need 20 forks from the same repo to contribute with 20 PRs.

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.

What happens to a forked repo if the original is deleted?

If the original repository is deleted, the fork remains. The question is about GitHub!

Why do we need to fork GitHub?

A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project.


Video Answer


1 Answers

If you want to follow the development of the project you've cloned, by convention, we add a upstream remote in addition to your origin remote. So you have to:

  1. Fork the project on GitHub.
  2. Rename the current origin remote (that track the upstream project) with a new name like upstream.

    git remote rename origin upstream
    
  3. Add your personal forked GitHub project as the origin remote.

    git remote add origin <URL of your personal github fork>
    

The idea behind that is to follow the naming conventions of origin for your personal repository and upstream for the project repository.

like image 59
Philippe Avatar answered Sep 20 '22 15:09

Philippe