Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping a fork up to date

Tags:

github

I wanted to commit somthing to a github repository, but I (obviously) didn't have any rights to do so. I made a fork of that repo, commited my changes and submitted a pull-request. Now, the problem is that after a while other people have made commits to the original repo, which means my fork is no longer up-to-date.

How should now update my fork? Is this (https://stackoverflow.com/a/23853061/5513628) still a valid way or do I have to delete my repo and make a new fork every time?

This is what the fork looks like in github desktop:

enter image description here

The pull request was made by me but the two commits after that were made by other people. They are not contained in my repo...

like image 507
MyNameIsHans Avatar asked Oct 02 '16 17:10

MyNameIsHans


2 Answers

To sync changes you make in a fork with the original repository, you must configure a remote that points to the upstream repository in Git.

Specify a new remote upstream repository that will be synced with the fork.

git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git 

You can check if it was succesful with:

git remote -v 

Then fetch it to update your project:

git fetch upstream 

Merge the changes from upstream/master into your local master branch.

git merge upstream/master 

At last, you can commit new update from original repository to your fork repository.

Shortcut: you can also combine the last two commands into a single command:

git fetch upstream git merge upstream/master 

Is equal to:

git pull upstream/master 

This information can also be found on GitHub here and here.

like image 110
Diki Ananta Avatar answered Sep 19 '22 20:09

Diki Ananta


Adding to Diki Andriansyah answer, rather than using

git merge upstream/master

try using:

git pull upstream master

This helped me :) .

like image 26
Yathartha Joshi Avatar answered Sep 22 '22 20:09

Yathartha Joshi