We help IT Professionals succeed at work.

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

Andrew Angell
on
647 Views
Last Modified: 2016-03-07
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!
Comment
Watch Question

Most Valuable Expert 2011
Author of the Year 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Andrew AngellCo-Owner / Developer
CERTIFIED EXPERT

Author

Commented:
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.
Most Valuable Expert 2011
Author of the Year 2014

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

Maybe there is a solution in using Composer?
Andrew AngellCo-Owner / Developer
CERTIFIED EXPERT

Author

Commented:
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.
Co-Owner / Developer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Andrew AngellCo-Owner / Developer
CERTIFIED EXPERT

Author

Commented:
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.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

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

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.