How to tell git that my local directory is a specific directory in the remote tree

78 views Asked by At

I have a shared git repository on bitbucket where I'm working on a part of a project and others are working on other parts. All the parts are each in a different folder On git the folder structure looks something like this:

rootdir
  part_foo
  part_foo2
  part_mine

On my filesystem however The structures of my c++ project looks like this:

rootdir
  bin
  src
    file1.cpp
    ...
    fileN.cpp
  test_data

The bin and test_data folder are not to be commited as they are for my use only.

So what I'd like to achieve is to have the content of my local src folder to be synced with the content of part_mine folder.

I've tryed both sparse-checkout and the solution proposed here, but they both are not the perfect solution as I end up having the part_mine folder created inside the src folder (or viceversa), which is kind of a problem for me.

So I'm asking if there's a way of telling git to think of my working directory as one specific directory in the remote tree. That would be that if I init and remote the git repository inside the folder src I can then tell git that I'd like to push/pull inside a specific folder (i.e. part_mine) and see all the file in there in src and viceversa.

Thank you for your help!

1

There are 1 answers

3
VonC On BEST ANSWER

The usual solution is to:

  • clone the repo in some folder external to your project (no need for sparse checkout here, unless the repo is really huge)
  • symlink src to rootdir/part_mine

For any git operation, you go to yourRepo (for git add, commit, push)

For the rest, you work in rootdir as usual.