DEV Community

Ryan Lanciaux
Ryan Lanciaux

Posted on

42 9

How should you ignore files for just you in git?

No, this isn't a post about .gitignore

The .gitignore file is a great way to exclude files from a repository for all users. This post is not about that.

I often want to ignore files that a tool / editor I use generates in a project. Others who are working in the project may not be using these same tools so adding to a .gitignore file may not be the best solution.

Exclude file

There is the concept of a local exclude file in git. It works just like .gitignore but the file is not checked in.

It's available at .git/info/exclude from a project directory.

Keep in mind

Files that should always be ignored should be specified in .gitignore. Files that you want to exclude locally could go in .git/info/exclude ๐Ÿ‘

(crossposted from ryanlanciaux.com)

AWS Q Developer image

Your AI Code Assistant

Ask anything about your entire project, code and get answers and even architecture diagrams. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Start free in your IDE

Top comments (9)

Collapse
 
shreyasminocha profile image
Shreyas Minocha โ€ข

Oh, that's new. I thought this would be about global gitignore. Thanks!

Collapse
 
dotproto profile image
Simeon Vincent โ€ข โ€ข Edited

If you commonly create files that you don't want to commit to any of your projects, you can also create a global ignore file.

$ git config --global core.excludesfile ~/.gitignore_global

For example, say you're on a Mac and you want to make sure you never commit the .DS_Store files generated by your OS, you could run the below command to add an ignore rule to your global list.

$ echo ".DS_Store" >> ~/.gitignore_global
Collapse
 
moigagoo profile image
Constantine Molchanov โ€ข โ€ข Edited

Knew about this trick but it never worked for me. Added a file to .git/info/exclude but it still gets tracked.

Is there anything else that should be done?

Collapse
 
ryanlanciaux profile image
Ryan Lanciaux โ€ข

Interesting- itโ€™s always worked for me when I do this. Are these files that are previously tracked?

Collapse
 
moigagoo profile image
Constantine Molchanov โ€ข

Yeah, that's why I'm trying to untrack them :-)

Collapse
 
moigagoo profile image
Constantine Molchanov โ€ข
Thread Thread
 
ryanlanciaux profile image
Ryan Lanciaux โ€ข

Oh good! If or doesnโ€™t end up working for you, please let me know and I can try to remember what I did in the past ๐Ÿ˜ƒ

Collapse
 
cescquintero profile image
Francisco Quintero ๐Ÿ‡จ๐Ÿ‡ด โ€ข

๐Ÿ˜ฎ๐Ÿค”๐Ÿค”

Collapse
 
hassamali profile image
Hassam Ali โ€ข

Man i wanted this so badly โ™ฅ๏ธโ™ฅ๏ธโ™ฅ๏ธโ™ฅ๏ธ

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

๐Ÿ‘‹ Kindness is contagious

Please leave a โค๏ธ or a friendly comment on this post if you found it helpful!

Okay