I have a git repository that contains several files that come from an upstream source. I have a few local modifications to these files, but they are largely the same as the upstream versions, and I would like to be able to stay in sync with upstream releases. I don't need upstream history, but if there is a new release, I'd like to be able to merge that in while still keeping my own changes. As a result, it's not as simple as just copying the upstream files into my repository, because that will result in my changes being lost, and it's a real pain to manually run vimdiff
or something similar to ensure my changes get added.
Right now I've come to a solution that looks like this:
- Create an orphan branch that is completely empty (call this
upstream
) - Add the upstream files to this branch (so they're the only thing in it)
- Merge
upstream
into my main branch, passing--allow-unrelated-histories
- Apply my changes to the files and commit
Now I should be able to bring in changes to upstream
and continue merging that, while keeping my changes intact. It seems to work but feels hacky. Is there a more appropriate solution to this problem?
Edit:
Here's a scenario that mimics what I'm doing: there is a header-only C++ library available for download somewhere. It's not in a Git repository, it's just a bare file somewhere that's periodically updated. I'm using that file, but I have some local changes to it. I want to be able to track changes in future downloads while still keeping my changes to the file (with conflict resolution when necessary). I want the file part of my repository, so I don't want to have downloading and patching be a part of the build process. I'd prefer to use Git to do the merging/conflict resolution.