Avatar of Andrew Angell
Andrew AngellFlag for United States of America asked on

How to use ignore everything but the files/folders I want in Git with gitignore..??

I have a CodeIgniter PHP library that I maintain.  I do not distribute all of the CI platform with the library.  I only distribute the library files themselves.  The thing is, the library files are scattered through the whole CI structure.  

As it stands now I have a git repo that simply has nothing but the library files in it, so I do my code adjustments in a separate location where CI is fully installed and then I have to copy over to my "library only" version of the files to submit into Git.  This makes the work flow cumbersome.  

What I need to do is ignore everything in the CI structure so that it doesn't get tracked except for my library files, which consist of:

application/config/paypal-sample.php
application/controllers/paypal/*
application/libraries/paypal/*
application/models/paypal/*
application/views/paypal/*

Everything else in the project should be ignored by Git.  Any information on how I can accomplish this would be greatly appreciated.  Thanks!
GitPHP

Avatar of undefined
Last Comment
Andrew Angell

8/22/2022 - Mon
SOLUTION
Ray Paseur

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Andrew Angell

I should have mentioned that I tried that already and it doesn't work.  The files under the root do work, but the folders don't.  I've read a lot about it and it basically says once you've ignored directories you can't un-ignore things inside them, so you have to do tricky things, but none of the tricky things people are saying are working for me.

For example, this sort of thing kinda works...

*
!**/
!.gitignore
!README.rst
!instructions.html
!application/controllers/paypal/**
!application/libraries/paypal/**

For some weird reason, though, that seems to work with the controllers, for example, but then it doesn't work for the libraries for some reason.  

Copying to another repo is what I'm trying to avoid.  Right now I have my local CI install with these library files in it, but every time I make changes and update then I have to go through and copy everything into my "library only" repo separate from this one.  It's just tedious.

I guess I could write a script, yeah, but then as things grow and new files are added or moved around, etc. I'd have to keep adjusting my script.

It's just so nice when I can work in a single project and have Git only track the exact files I'm working on.  I typically work with WordPress plugins and since they reside entirely in a single directory it's much easier to work with.  When these files are all spread out like this it's sort of a PITA.
Ray Paseur

When these files are all spread out like this it's sort of a PITA.
Amen!

Maybe there is a solution in using Composer?
ASKER
Andrew Angell

Well, yes.  Sort of a long story, but I have a standard PHP class library for PayPal that I've maintained for years.  A while back (before I knew about Composer) I created a CodeIgniter specific version of the library and I was maintaining them separately.  

My standard PHP class library now works with Composer, and I've been trying to steer people that direction, but the CI specific library is still the top hit on my site and seems to be what most CI users are comfortable with.

As such, I decided to improve upon it a little bit, which is why I'm getting back into this now and trying to figure this out.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
Andrew Angell

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Andrew Angell

Expert info was technically correct, but just wasn't working out for what I needed here specifically.  The way I did it and posted is the only way I was able to find it could be done.