This question is related to, e.g., How to move files from one git repo to another (not a clone), preserving history Detach (move) subdirectory into separate Git repository but the problem (or at least the solution, I think) is different. I have the following directory structure:
abc/
.git/
def/
file1.txt
file2.txt
xyz/
file3.txt
The directory abc
is the root of a git repository, say repo1
.
What I want is to put file2.txt
in a different repository, repo2
(local and linked to a remote). However, I do not want to move file2.txt
out of the directory (as in the related questions). All other files and folders (def, file1.txt, xyz/*
) have to stay in repo1
.
When I do git commit
or git push
, changes to file1.txt
should go to repo1
and changes to file2.txt
should go to repo2
.
As a workaround, I could make an additional directory in def
and move file2.txt
there, if that makes it any easier. However, I don't want to move file2.txt
out of the current tree.
The history of file2.txt
does not necessarily need to be preserved in this move.