Video in progress

Staff 🌿 Git

The company forked an open source project (Keycloak, say) and made its own changes. How do you stay in sync with upstream?

I keep the fork's changes minimal and isolated: through a plugin/extension if possible, otherwise as a clear set of patches rebased on top of every upstream release tag. A regular update cycle and sending changes back upstream are the main rules.

📖 Answer

Forking is easy, maintaining the fork is expensive. Catching up a fork that has not been updated for a year usually turns into several weeks of work, and security fixes wait during that time.

The strategy:

  1. Avoid the fork. In projects like Keycloak there are SPI and extension mechanisms, and many changes can be done in a separate JAR without forking at all.
  2. Patches are small and commented. Each commit is one logical change, with the "why" in the message and a link to whether it was sent upstream.
  3. Rebase on release. When a new upstream tag comes out:
    git fetch upstream --tags
    git switch -c company/26.1 company/25.0
    git rebase --onto 26.1.0 25.0.3 company/26.1
    
    As a result company/26.1 = upstream 26.1.0 + our patches. In a fork maintained with merges, after a few years you cannot answer "which changes are ours?", while with rebase git log 26.1.0..company/26.1 gives you the list.
  4. Keep git rerere on, for the conflicts that come back with every release.
  5. Sending back upstream. For each patch, a task "PR to upstream". The accepted ones disappear on their own at the next rebase, and the fork shrinks.
  6. The update rhythm. Minor releases every quarter, security patches immediately. In CI, the upstream tests plus our additional tests.

One thing: the license. If you distribute the forked code (to a customer on-prem, for example), the license terms need to be checked with the legal team. This is not a Git question, but at the staff level this is exactly where the trouble shows up.