Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Re-fork a repository on GitHub

I've forked a repository on GitHub and have a quite an extensive commit/pull/push history, which I need to keep.

The owner of the main repository has created some new branches. How can I clone these branches into my forked copy, without deleting the fork and cloning from scratch?

like image 436
binks Avatar asked Nov 05 '14 12:11

binks


People also ask

Can I delete a forked repository and fork it again?

Note that after deleting the repository, the action cannot be undone. Also note that if you are deleting a forked repository, deleting it will only remove it (including any changes you have made to it) from your own GitHub - you won't accidentally delete the original project (phew).

Can I fork a repository twice?

You are unable to fork a repo twice on Github (as of late 2021) but if you want to build on the same repo multiple times, you can use the "Import Repository" option and feed it the URL used to clone.

What happens if I delete a forked repository in GitHub?

Deleting a repository will permanently delete release attachments and team permissions. This action cannot be undone. Deleting a private repository will delete all forks of the repository.


1 Answers

You'll want to add the other repository as a remote for your own one.

Got to where you've got your repository on your computer and open git Bash and do:

git remote add upstream <address of the repository you cloned from>

Then whenever you need to update your fork just do:

git fetch upstream
git rebase upstream/master

That will reapply whatever changes are on your current branch on top of any changes from the other repository. Note to make things easier I usually leave the master branch on my repository untouched and only work in branches. Then whenever I need to update I just rebase master and rebase my other branches on top of that.

Don't know about getting other branches for upstream though but this answer may be of help: How do I check out a remote Git branch?

like image 103
Sollace Avatar answered Oct 12 '22 01:10

Sollace