Posted In GitHub

Keep Your Forked GitHub Repository In Sync

Fork something? Update your fork with changes from upstream

I fork a LOT of things I see on GitHub. It’s habit, most I never touch, but others I do keep up on.

It’s nice to be able to merge changes that the original authors made, back into my fork. Especially if a major feature was added in after I made my fork. Keeping your forked GitHub repository in sync with that of the original repository requires you to add a new git remote, merge the upstream code with your fork, and then push master back to your fork on GitHub.

Here’s how it’s all done

First, you’ll need to add an upstream remote.

There’s really only two steps involved. Fetching updates from the newly created upstream remote and then merging the changes into your code.

To fetch updates from the upstream remote, do this:

Now we’ve got all the changes made to the original “forked” repository. All the changes are stored in a local branch, upstream/master. Neat!

Now, make sure you’re on the branch you’re supposed to be, if you don’t know, you want master. To ensure you’re on the local master branch, do this:

Now that we’re on our local master branch, we can merge the changes from the original repository. To merge from the upstream/master branch to your local master branch, do this:

That’s it! You can now update your fork on GitHub with updates from the repository you originally forked.

Now, at this point, your fork on GitHub should contain changes from the “original” repository that you forked, as well as any changes that you made to your own fork. Keep an eye on the “original” repository and perform these steps again, except for adding the upstream remote, you’ll only need to do that once.

For more information, checkout this piece from GitHub Help.

Do you use GitHub?

View Results

Loading ... Loading ...

Well, now what?

Work with Me

I'm available for hire and always taking new clients, big and small. Got a project or an idea you'd like to discuss? Startup plan but no developer to make it happen? Just get in touch, I'd love to see if I can help you out!

Leave some Feedback

Got a question or some updated information releavant to this post? Please, leave a comment! The comments are a great way to get help, I read them all and reply to nearly every comment. Let's talk. :) is proudly hosted by DigitalOcean

About these ads