How to commit and version changes in a git fork/branch but not merge them back

Published 2017-09-21, 11:38

Recently I tried to figure out how to have both a production and staging environment of a Jekyll website hosted with Github Pages.

This turned out to be not that simple, as both repositories (Github Pages can only host one branch per repository, so you need two – one organization repository and one personal for example) need to have a CNAME and _config.yml file with different content.

So the actual question to answer was how can one commit and version changes to files in a git fork/branch but then not merge them back into the source, while still having a fully merged branch (so actual changes can be merged back via Pull Requests)?

The answer is to use the ours merging strategy when merging the changes that should be skipped:

  1. Assume we have our production repo and staging repo both checked out locally, for now being identical (and having the same CNAME and _config.yml).
  2. Check out staging, make the changes to the files and commit and push them.
  3. If we were to do a normal merge to production, this change would now get merged over.
  4. But now we run these commands:
    git checkout production
    git merge --strategy=ours staging

    (Source)
    --strategy=ours makes sure that during this merge, the production file remain unchanged. But the commit is still marked as merged.
    If we want, we can now also edit the merge commit messageto be a bit more descriptive what we just did: We merged the two branches, but made it keep „our“ (in this case: production) version of the files.
  5. Then push the changes to production:
    git push production production:master

Your next changes to staging can the be merged with production normally, without getting the CNAME and _config.yml changes.

Topic(s): Technik 1 single comment - :/

Diskussion zum Artikel

» Selbst kommentieren

  1. ( 1 )

    Yep, great design choice Jan. Super readable…

    Meh.

    Comment von Jan am 21. September 2017

Selbst kommentieren

Trackback-URI, Kommentarfeed. XML-Feed





16 queries. 0,114 seconds.