Yarin Yarin - 1 year ago 74
Git Question

Using .gitignore to ignore everything but specific directories

My issue is that I have a bunch of WordPress websites in my git repo, of which I want to selectively commit only the content of my

folders, while ignoring the rest of the redundant files found in WordPress.

I've used .gitignore files to ignore file types before, but can it be used the other way around- that is to ignore everything BUT a certain folder path?

root (git repo)

- / wordpress

- - / (WordPress Site 1)/wp-content/themes

- - / (WordPress Site 2)/wp-content/themes

- - / (WordPress Site 3)/wp-content/themes



Based on the answers I did the following, but it's not working. Any ideas?

# Ignore everything:
# Except for wordpress themes:

I've also tried the following variations:


None of these read my

Answer Source

Here's how I did it - you essentially have to walk up the paths, you can't wildcard more than one level in any direction:

# Ignore everything:

# Except for the themes directories:


Notice how you have to explicitly allow content for each level you want to include. So if I have subdirectories 5 deep under themes, I still need to spell that out.

This is only how it worked for me. If someone cares to offer a more informed explanation by all means.

Also, these answers helpful:

NOTE: I tried using double-wildcard 'globs' but according to this that functionality is system dependent and it didn't work on my mac:

Did NOT work:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download