Reputation: 38714
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.
Upvotes: 12
Views: 2628
Reputation: 31197
If you want to follow the development of the project you've cloned, by convention, we add another remote (named upstream
) in addition to your origin
remote.
So you have to:
Fork the project on Github.com website.
Rename the current origin
remote (that tracks at the moment the upstream project) with a new name like upstream
.
git remote rename origin upstream
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 repositoryupstream
for the project repository (to be able to sync your personal repository with developments made in the upstream repository)Upvotes: 14
Reputation: 11
The overall strategy is as follows:
git remote -v #shows you the names of the remote repos
git remote remove {Name of the remote repo(s)}
git remote add {url of the desired remote repo}
Upvotes: 1
Reputation: 887797
You simply need to add your fork as a remote in your existing clone:
git remote add <any name> <URL of fork>
You may also want to git remote rm
the original repo.
Upvotes: 1