Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to conveniently sync a file between two git repositories

Tags:

git

linux

unix

sync

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?

like image 297
RevMoon Avatar asked Oct 05 '13 14:10

RevMoon


People also ask

Is it possible to defer sync with the repository as per convenience?

In their own local copies of the project, they edit files and commit changes as they would with SVN; however, these new commits are stored locally - they're completely isolated from the central repository. This lets developers defer synchronizing upstream until they're at a convenient break point.

How do I move files between Git repositories?

Merge the files into the new repository B. Step 2: Go to that directory. Step 3: Create a remote connection to repository A as a branch in repository B. Step 4: Pull files and history from this branch (containing only the directory you want to move) into repository B.


1 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.
like image 155
VonC Avatar answered Oct 22 '22 16:10

VonC