Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git ignore specific directories

I wanted to recently upload my dotnetnuke website on git, now my website has gigs of images which i don't want to upload over git.

I was searching on GIT and came across .gitignore file which gets created during repository creation, GIT has a documentation about ignorning files/folders and it's specific sub-folder, however it does not seems to work in my case.

Here's my folder structure:

*******Updated*******
.gitignore
public_html/Portals/_default/
public_html/Portals/0/
public_html/Portals/1/
public_html/Portals/110/

Now i want to ignore all folders under Portals except Portals/_default. I tried based on the specification from GIT:

Example to exclude everything except a specific directory foo/bar (note the /* - without the slash, the wildcard would also exclude everything within foo/bar):

    $ cat .gitignore
    # exclude everything except directory foo/bar
    /*
    !/foo
    /foo/*
    !/foo/bar

Below is what i tried:

!/Portals
/Portals/*
!/Portals/_default

But this does not seems to work at all.

Can anyone get me in right direction.

like image 288
Abbas Avatar asked Aug 04 '26 11:08

Abbas


1 Answers

From the git documentation for gitignore:

Example to exclude everything except a specific directory foo/bar (note the /* - without the slash, the wildcard would also exclude everything within foo/bar):

$ cat .gitignore
# exclude everything except directory foo/bar
/*
!/foo
/foo/*

Tada!

like image 104
msw Avatar answered Aug 06 '26 23:08

msw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!