0

I've got a new project that will be using Codeigniter as the framework, Flexiauth for the user login stuff, and then my own custom code for my application. Both codeigniter and flexiauth use Git and I'd like to be able to do pulls from those to keep my code up to date.

Do I add each as a seperate remote repository and just do pulls? Wont that create conflicts?

Is there a better method for handling multiple git repositories as components of a larger project?

Citizen
  • 12,430
  • 26
  • 76
  • 117

2 Answers2

2

Yes, there is. Git supports submodules.

I recommend the relevant section of the Pro Git book online as a good starting point for figuring this out, but the basic idea is you add a submodule using the following syntax:

git submodule add git://github.com/chneukirchen/rack.git rack

where rack is the folder you want to set up as a submodule. When cloning the repo, you need to run the following commands after the clone to fetch the submodules:

git submodule init
git submodule update

That way, you keep the third party library out of your repo entirely and only record it as a submodule.

Alternatively, this is the problem Composer is meant to solve. The Laravel 4 framework is actually built in such a way that all of its components are installed with Composer, and you can just run composer update to update them all. You could conceivably use Composer with CodeIgniter (Phil Sturgeon wrote a blog post on doing so at http://philsturgeon.co.uk/blog/2012/05/composer-with-codeigniter), however Flexiauth doesn't appear in the repository at https://packagist.org/, so I would go with using Git submodules.

Matthew Daly
  • 9,212
  • 2
  • 42
  • 83
1

I'm no git expert and it might not be correct but what I'd do is initiate the git repo for the libraries in an external_library, third_party or some folder from which you import to your project. Then when it comes time to update, cd into the folder>project folder and do a git pull origin master or whatever you named it.

I think it's typical to have git within git i.e.:

myproject
    .git <- root repo for whole project
    application
    system
    third_pary
        cool_library
            .git <- repo for cool_library
            cool_folder
                some_lib.php
        other_cool_library
            .git <- repo for other_cool_library
            neat_libs
                neato.php

From within the root of myproject, git commands will only affect myproject's repo. So

$cd myproject
myproject$ git commit -a -m"neat"

will commit the changes to your myproject repo; all changes in all folders committed (but, if you made a change to /myproject/third_party/cool_library/cool_folder/some_lib.php, you should cd into /myproject/third_party/cool_library/ and do a git commit before committing in /myproject/).

As for pulls:

$cd myproject
myproject$ git pull origin master

will pull into myproject; the other .gits in the third_party folder will be unaffected (unless of course someone else pushed changes to myproject that had changes to the third_party repos.

So, tl;dr, pulling into your project root will not cause the subfolder repos to pull from their origins. When you need to update, change into the libraries' directory and do a pull there.

In other words, given the above file structure, if there was an update to cool_library that just came out, this is what I'd do:

$cd myproject
myproject$ git commit -a -m"committing before updating cool_library"
myproject$ cd third_party/cool_library
cool_library$ git pull origin master
cool_library$ cd ../../
myproject$ git commit -a -m"commiting after updating cool_library"
stormdrain
  • 7,915
  • 4
  • 37
  • 76