Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to I switch to a git branch that ignores files without deleting these files?

Tags:

git

gitignore

I have branch master that ignores .idea in its .gitignore. From that, I created branch noIgnore that has no .gitignore.

I found that checkout master deletes .idea.

That's not the behavior I want. I want to keep .idea, just not track it, not on master. How do I do that?

like image 999
Irina Rapoport Avatar asked Oct 30 '22 21:10

Irina Rapoport


1 Answers

You could stop tracking changes for a file in repo

git update-index --skip-worktree .idea

Since you're tracking it in the other branch, then when you make changes you'll want to start tracking changes again

git update-index --no-skip-worktree .idea

When you get tired of doing this manually, you could create a post-checkout hook if on master, stop tracking, else start tracking.

like image 119
Jeff Puckett Avatar answered Nov 15 '22 06:11

Jeff Puckett