Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I add a .gitignore file just for me that overrides the project .gitignore?

Tags:

I am using Git in Android Studio on a OS X machine, and I would like to have a personal .gitignore file that overrides the .gitignore that are in the project (I want mine to ignore .iml files). Can this be done and how?

I have tried to create a .gitignore file in my home dir with the following lines in:

# Android Studio .*.iml *.iml

And the I have used this command to make git use my file git config --global core.excludesfile ~/.gitignore, but it does not work.

Any ideas?

like image 969
Neigaard Avatar asked Sep 18 '14 12:09

Neigaard


People also ask

Can I override Gitignore?

For those who don't mind modifying the . gitignore file, you can override a rule by adding ! in front of a filename or folder. Use * to select the files in a folder and ** to select the files in subfolders recursively.

Can you have more than one Gitignore?

You can have multiple . gitignore , each one of course in its own directory. To check which gitignore rule is responsible for ignoring a file, use git check-ignore : git check-ignore -v -- afile .

What is the purpose of adding a .gitignore file to a git repository?

The purpose of gitignore files is to ensure that certain files not tracked by Git remain untracked. To stop tracking a file that is currently tracked, use git rm --cached.


1 Answers

Instead of creating a new .gitignore file, you should use the .git/info/exclude file to setup ignore rules specific to your clone of the repo.

So, basically, go to your project root, and run

cd $PROJECT_ROOT echo "*.iml" >> .git/info/exclude 

Note that the the pattern *.iml will take care of files of kind .*.iml as well, so you can make do with one ignore rule.

Also, this complements the existing ignore rules in .gitignore and ignore rules of .gitignore will still be applied.


It seems you are already tracking the .iml files in your Git repo, so you can try removing them from Git using

git rm -r *.iml git commit -m "removed *.iml" 

Note that this will untrack them from the master repository as well once you do a push.

Otherwise, you can use git update-index --assume-unchanged <filename> to ignore changes to those files locally. And afterwards, the gitignore rules should work all right.

like image 86
Anshul Goyal Avatar answered Sep 19 '22 13:09

Anshul Goyal