Git: How to handle git libraries in project
Solution 1
Sure do the following:
- Remove the 3rd-party-folder which you might have added already
-
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"
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
Related videos on Youtube
dhrm
Updated on June 04, 2022Comments
-
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 over 12 yearsThank you. Couldn't I use this instead
git submodule add https://github.com/AlanQuatermain/AQGridView.git Libraries/AQGridView
instead of[email protected]:...
? -
dhrm over 12 yearsHow 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 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 ᚅᚔᚈᚄᚒᚔ over 12 years@DennisMadsen: You can use any repository path that Git will accept; SSH, HTTP(S), Local path, etc.
-
Besi over 12 yearsFor anyone who's interested. The screenshot were done with Git Tower, which I can recommend using.