Alex Feinman
Alex Feinman

Reputation: 5563

How can I manage overlapping repositories in git, including files in the same directory?

I have a complex repository where sometimes the logical boundaries between code segments crosses directory boundaries. Sometimes a single file in directory X really needs to go with files in directory Y.

E.g., pretend I have a central repo that looks like this:

a/foo
a/bar
b/baz1
b/baz2

...and I want my local repository to end up with a/* and b/baz1, but not b/baz2. The other files should end up in another repository.

(Yes, the long term solution is to move the files, but while I am working on that refactoring, I need to version-control the files appropriately.)

Can I use git to do this?

Upvotes: 3

Views: 2278

Answers (2)

Greg Hewgill
Greg Hewgill

Reputation: 993901

You can do this with Git's sparse checkout feature (if that link still doesn't work, try this one or see man git-read-tree). Run the following commands in your cloned repository:

git config core.sparsecheckout true
echo '*' >.git/info/sparse-checkout
echo '!b/baz2' >>.git/info/sparse-checkout
git read-tree --reset -u HEAD

This will delete the existing b/baz2 file from your local working directory. It's still in the repository, but your local Git will not care about the fact that it's gone from the working directory.

Upvotes: 2

hoppa
hoppa

Reputation: 3041

If you want to refactor existing code, just create a feature branch and change all the stuff you need to change (even inside different directories). When you're done simply merge the changed stuff back into master or into another branch you're using.

To be honest I don't quite see the problem.

Upvotes: 0

Related Questions