How to "force" ignore a file?

I have this .gitignore:


I need to ignore myproject/ because they're different in the development environment and the production environment but git still tracks the file. I tried to ignore it in sourcetree but the option appears inactive. Any Ideas?

2 answers

1 accepted

1 vote
Accepted answer

I found the answer here

Basically clean the index and cache, then ignore the file

You should check if your .gitignore file is being read at all or not. It could be that there exists a global gitignore or a custom-specified git ignore file, specified on the command line, when the git runs. However, try adding a line like:


to your .gitignore and of course create that file, just to make sure that .gitignore file is being respected.

If everything is ok with your .gitignore file, than it might be the case where the git has already tracked/staged/pushed some previous versions of that file, so you might want to remove it from the remote git repository too. For that purpose, try using:

git rm myproject/

(don't forget to backup your file first, since that command will remove the local copy of the file also). After that, push your changes and just create a new file myproject/ and it shouldn't be tracked any more (according to .gitignore).

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Friday in Off-topic

Friday Fun: Dry T-Shirt Competition - What's your BEST (Atlassian) T-Shirt!?

[Note: So it was my turn for Friday Fun and sadly I was sick thanks to rubbish sinus infection... so apologies to most of Europe and Asia for the delayed post. However, I finally got out of bed for t...

292 views 21 4
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you