scibuff
scibuff

Reputation: 13755

How to correctly sync the master and branches on a forked repo from github

I have forked a repo on github. Then I created a new branch for a feature I'm adding (lets call the branch 'my-new-feature'). I've worked on my branch a bit and pushed all my work back to github (the 'my-new-feature' branch). Now, the user has made numerous changes to the upstream.

Questions:

1) What is the correct way to sync my branch (as well as my forked master) with the upstream?

git checkout master
git fetch upstream
git merge upstream/master

git push origin

2) Is it possible to sync my forked master and all my branches all at once, or do I have to do it one by one? i.e. after I've updated the forked master, do I need to repeat with all my branches:

git checkout my-new-feature
git fetch upstream
git merge upstream/master
git push origin my-new-feature

or am I being dumb and there's a much easier way to do this?

thank you

Upvotes: 1

Views: 353

Answers (1)

matt
matt

Reputation: 534925

Instead of doing any of the work of keeping origin and upstream synchronized on your machine, you could ask github to pull down the changes from upstream for you. I mean, that is sort of the point of a fork. The only reason to do this on your machine is if you need "manual" fork management.

If you do decide to do "manual" fork management, there is no reason to fetch and merge feature from upstream — because, by definition, upstream doesn't have it. So, the first thing you said is the usual thing, if you don't want to do it all on github. Fetch upstream, merge into master, push to origin (or not, if no one is sharing it with you there is no rush after all), and now switch back to feature and proceed as if there were no upstream.

Upvotes: 1

Related Questions