28

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?

RevMoon
  • 859
  • 1
  • 9
  • 16
  • Hi, you're pretty much named most of the things crossing my mind. If you're only concern is not having to update manually (you still need to commit and push in two diff repos) I would go with the symlink, the hard one. – bitoiu Oct 05 '13 at 14:55
  • 2
    @bitoiu Oh, I thought hard link does not work. Apparently, it does. Although it has to be reset after checking out. – RevMoon Oct 05 '13 at 18:10
  • 2
    In my experience git breaks hard links -- its not a viable option. – Merlin Dec 04 '19 at 05:33

1 Answers1

13

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.
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 3
    oh, great! But can you provide some examples for your answer? – gaussblurinc Dec 20 '13 at 12:58
  • @gaussblurinc in that post-commit hook, you need to list all changed files in order to detect your file and process it: http://stackoverflow.com/a/4206210/6309 – VonC Dec 20 '13 at 13:11
  • sure, ok, but how can I copy file's changes to another git? Not entire file but it's changes? – gaussblurinc Dec 20 '13 at 13:15
  • 1
    @gaussblurinc copying the entire file would be easier. If you want to only copy the changes, you need to make and apply a patch: http://stackoverflow.com/a/12320940/6309 – VonC Dec 20 '13 at 13:28