Home » Git » How to conveniently sync a file between two git repositories

How to conveniently sync a file between two git repositories

Posted by: admin November 15, 2021 Leave a comment

Questions:

I have two git local repositories. Both share an identical file, under a different path and under a different name. Currently, when I make changes I have to copy the file from one directory to another.

Is there an alternative way to keep them in sync without manually overwriting the file? I don’t want to create a separate repository for this file. I thought one of the following things would work, but apparently, they don’t:

  • git submodule
  • git subtree
  • symlink soft
  • symlink hard

What else is there?

Answers:

The only other alternative would be a post-commit hook on repoA, which would, on each commit:

  • check if the file is part of said commit
  • copy it in repoB with the right path.