Link to home
Start Free TrialLog in
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!
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Andrew Angell

ASKER

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.
When these files are all spread out like this it's sort of a PITA.
Amen!

Maybe there is a solution in using Composer?
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.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.