Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply changes from a repo to its fork?

So I originally cloned a repo thinking I wouldn't make changes and eventually decided to fork my own copy for personal use (it's a dotfiles repo). If I want to continue changes from the fork, what's the cleanest way to copy local commits from the original clone over to the forked repo?

Looked around and couldn't find exactly what I want here.

Clarification:

I have two repos now on my computer, one that's a clone of the original repo, and another a fork from the same repo. I made changes to the clone, but am hoping to move these local commits over to the fork.

like image 580
Justian Meyer Avatar asked Sep 24 '15 18:09

Justian Meyer


People also ask

How do I pull changes from main repo to fork?

To pull down (i.e. copy) the changes merged into your fork, you can use the Terminal and the git pull command. To begin: On your local computer, navigate to your forked repo directory. Once you have changed directories to the forked repo directory, run the command git pull .

How do I fork an existing repo?

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. Source: GitHub Guides.

Does forked repo automatically update?

Sync from the UI Clicking on that you have the possibility to compare the changes made in the source repo with the ones made in your forked repo, and also to automatically fetch and merge them into your repo.

Can you fork a branch from repo?

You can only fork a repo. However, you can get the end result of what you want by running single-line piped command after your clone your fork locally.


2 Answers

The usual way to do this would be with git pull, just as you would when you want to merge any commits from another repo.

like image 117
Caleb Avatar answered Oct 20 '22 14:10

Caleb


Let's say you have main Repo as R, Original clone as C and current Fork as F. You want to get changes from C into F, without disturbing R.

You can achieve this by setting a remote upstream and syncing your fork.

Step1. To set upstream refer: https://help.github.com/articles/configuring-a-remote-for-a-fork/ Sitting in the branch of F, you can set upstream(or name it anything else you want to) to C. run:

git checkout <branch of F>
git remote add upstream <repo URL for C>
git remote -v

Step2. Syncing your fork. Refer: https://help.github.com/articles/syncing-a-fork/ run:

git checkout <branch of F>
git fetch upstream
git merge upstream/<branch of C>

This should bring changes from C into F. Just make sure you ensure the right branches are mentioned in the git commands.

like image 39
codePrady Avatar answered Oct 20 '22 12:10

codePrady