Git: How to handle git libraries in project

19,898

Solution 1

Sure do the following:

  1. Remove the 3rd-party-folder which you might have added already
  2. Open your Terminal and execute the following commands

    cd /path/to/your/main/repo
    git submodule add [email protected]:someuser/somerepo.git somerepo
    git commit -m "Added submodules"
    
  3. Now instead of copying those files you'll have a reference to the other repository in your project:

Edit:

Now if you want to update the submodule to a more recent commit you can do the following:

cd somerepo
git pull # You can also checkout a branch / tag etc.
cd ..
git add somerepo
git commit -m "Telling the main repo to update the reference to the referenced repo"

Solution 2

You can use git submodule and clone repositories like this

Share:
19,898

Related videos on Youtube

dhrm
Author by

dhrm

Updated on June 04, 2022

Comments

  • dhrm
    dhrm almost 2 years

    I've a Xcode project which itself has Git Source Control. In a Libraries folder I've cloned eight other Git project from GitHub. They are located inside my own Git repository and I've added all these libraries to my git in a commit.

    Instead of having the code of all these git libraries in my repository, is there a way to let git download their code from their repo when I make a clone of my repo? Or is it normal to include other git repos inside a project?

  • dhrm
    dhrm over 12 years
    Thank you. Couldn't I use this instead git submodule add https://github.com/AlanQuatermain/AQGridView.git Libraries/AQGridView instead of [email protected]:...?
  • dhrm
    dhrm over 12 years
    How can I update these submodules? Are they pulled automatically when I pull my repo or do I have to go inside their folder and make a git pull?
  • Besi
    Besi over 12 years
    @DennisMadsen Yes you can do a git pull which does pull any changes in somerepo however, you have to tell your main repository to update the reference too. See my updated post. BTW: I find submodules quite handy since you don't have to duplicate code from repositories, that are already accessible for you via git.
  • Justin ᚅᚔᚈᚄᚒᚔ
    Justin ᚅᚔᚈᚄᚒᚔ over 12 years
    @DennisMadsen: You can use any repository path that Git will accept; SSH, HTTP(S), Local path, etc.
  • Besi
    Besi over 12 years
    For anyone who's interested. The screenshot were done with Git Tower, which I can recommend using.