Search code examples
gitgit-rebasegit-clonegit-remotegit-fork

collaboration with shallow git clones


How can I create a shallow clone of a single branch that can be pushed to a new remote and later be reintegrated into the original remote?

I need to send code to a customer. That customer wants to make changes that I need to integrate into my code base later. However, I cannot give the customer a full clone.

I can create a clone that is exactly what I want the customer to have.

git clone --branch customer-release --depth 1 url

I can remove my remote, make commits on a new branch (as the customer would do), add my remote again, and push the customer branch for integration onto my remote.

However, I cannot push the shallow clone onto a newly created remote (as the customer would want to do).
I experimented with orphan branches and rebasing but was ultimately unsuccessful.


Solution

  • To avoid any mistake, I would create a separate repo with just the code you want.
    There would not be any history in it, but such a repo would be easy to push and collaborate on.

    Once you want to re-integrate new commits from that separate repo to your own original repo, you can use format-patch/apply to export/re-import the relevant commits.

    That seems safer than trying to isolate a branch from a full repo.