gitgitignorebranching-and-merging

Delete and stop tracking folders from client branch but keep them on main product branch


I've branch out client branch (C) from main product (P) branch which I am adding features as per request. The main product branch contains all folders/files for every client with the main product code. Is there a way to delete and stop tracking other clients' folders in branch C but can still merge C to P without P removing the folders?

I've tried git rm for the unwanted folders and adding them in .gitignore in C branch, but when I try to merge P is deleting them as well.


Solution

  • What you are looking for is sparse checkout. git-scm.com/docs/git-sparse-checkouteftshift0

    git sparse-checkout set <unwanted-folder>
    

    This resolved my issues since it stops tracking unwanted folders on my checked-out branch but kept them on remote product branch.

    git sparse-checkout disable
    

    to disable this configuration on my local environment