Home > Net >  Git rm --cached only for one branch
Git rm --cached only for one branch

Time:08-01

On my development branch, I didn't want to track some json file. So i git rm --cached jsonFolder and added it to gitIgnore.

I do need to keep it on my main branch.

Problem is, once on main branch, when i git merge development, it erase my jsonFolder.

I tried doing a git restore --source main --worktree jsonFolder Then wanted to git add jsonFolder to track it.

Tells me The following paths are ignored by one of your .gitignore files which makes sense.

So I tried to git checkout --ours .gitignore which tells me Updated 0 paths from the index, which is weird, I checked, and the gitignore on my main branch does not include jsonFolder.

I had to manually changed my .gitignore then git add jsonFolder for it to be tracked.

Seems very cumbersome. What is a proper workflow to have a folder ignored in one branch, but not another ? Also, why did git checkout --ours .gitignore didn't work?

Thanks

  • Related