6

I can think of a few ways to keep a fork up-to-date:

  • git pull, apply changes using a script (pull automatically merges)
  • git pull, merge (possible conflicts?)
  • git fetch
  • maybe using another branch some way?

Question: What's the most efficient way to keep a fork up-to-date?

Community
  • 1
  • 1
  • The first and the second options are the same. `git pull` is a shortcut for `git fetch` followed by `git merge`. – axiac Dec 05 '16 at 21:20
  • Possibly using a cron job to do the above might be the most efficient from your point of view as a developer – scrowler Dec 05 '16 at 21:37
  • 2
    What parts of the the fork do you want to keep up-to-date with the upstream project? Just master? Tags? Other branches? What do you mean by efficient? Easy to execute? The fewest steps? The easiest to integrate? And are you looking to contribute your changes back or maintain a long-term fork? It makes a difference in how you want to go about managing your changes. – John Szakmeister Dec 05 '16 at 21:50
  • Just master. Easy to integrate, the most conflict-free. – Samuel Shifterovich Dec 05 '16 at 21:55

2 Answers2

8

Keeping a fork up-to-date is about the original repo: you need to base your local work on top of an up-to-date image of said original repo.

Generally, in a triangular workflow, the original repo is called upstream.

So all you need to do is:

git fetch upstream
git rebase upstream/master
git push --force

That will rebase your current branch on top of an updated upstream/master, and then you can force push (provided you are the only one working on your own fork).

triangular workflow

This is very different from a pull, as it does not merge the branches from upstream to your own local branches.
Rather it replays your lcoal work on top of those branches, ensuring that a future pull request will be trivial to accept back into the original repo (fast-forward merge, as you are publishing only new commits on top of the most recent state of the upstream master branch)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

You can use git pull to fetch the latest changes from remote as well as merge these changes locally. This will give you the most updated version for the branch you are on currently. This should be sufficient to keep your forked branch up-to-date.

By simply doing a git fetch you will just be updating your remotely tracked branch with new changes. You will then have to implement a merge command if you want to see the new changes locally.

ValyriA
  • 157
  • 2
  • 9