Git ignore all files except some files

Sometimes you may need to ignore all of files except only some little files. does gitignore support that ?

The answer is yes. you can use not operator ! like the following.

If we want to ignore all files inside directory_name except __init__.py

# add ignore all in the top of .gitignore file
directory_name/*

# then put the file names you want to be included and put ! operator 
# before it.
!__init__.py

3 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Select your currency
EGP Egyptian pound