26

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?

1

2 Answers 2

29

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"
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you. Couldn't I use this instead git submodule add https://github.com/AlanQuatermain/AQGridView.git Libraries/AQGridView instead of [email protected]:...?
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?
@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.
@DennisMadsen: You can use any repository path that Git will accept; SSH, HTTP(S), Local path, etc.
For anyone who's interested. The screenshot were done with Git Tower, which I can recommend using.
3

You can use git submodule and clone repositories like this

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.