How ignore gitignore file in merge

Hello,

I’m using two branches in my project: main and dev. I want to maintain separate .gitignore files for each branch. In other words, when I merge from dev to main, the changes to the .gitignore file should be ignored, but if I make changes to the .gitignore file and push to the same branch, those changes should be tracked. how can i make this work?

Thank you!