Please note that I am new to Git.
I have two repos:
The main repository is Libgdx REPO and all of my work goes into this repository, mainly in the gdx-sqlite project. Since I wanted gdx-sqlite project to appear as a separate repository, what I did was:
- Created a new repo on GitHub (gdx-sqlite REPO)
- Created a local repo (nested inside the local libgdx repo) on my machine
- Pushed all the code of the local nested repo to remote gdx-sqlite REPO
This resulted in everything going wrong and I assumed that nested repository was the main culprit. Later I deleted the local nested repository and reverted to a previous commit. I have found out that a solution to this kind of problem is Git Submodules but I am completely lost at what I am trying to achieve which is as follows.
Now how am I supposed to achieve this in light of the following:
- I want to create a new repo located at "gdx-sqlite REPO" that should always reflect the changes I make to the project located at "https://github.com/mrafayaleem/libgdx/tree/master/extensions/gdx-sqlite"
- Anyone who sends a Pull Request to "gdx-sqlite REPO" should be able to pull all the dependencies (that is the complete libgdx REPO) so that he can work on that extension right away.
How can this be made possbile?
You're right. The good approach for this kind of situation is to use Git submodules. This is the best way to handle dependencies in Git.
As gdx-sqlite is an extension of your main project Libgdx, you could do it this way to add it as a submodule:
Then to clone your project (and all its submodules):
Or for you (with write access):
You should take a look at git subtree. This allows you to add one or more git repository as subtrees.
One of the drawbacks is, that you need to be carifully with your commits. If you commit several changes with files in different sub trees, than all the repositories will have this commit in its history. This can be really nasty if you try to pin down a change in one repo and can not find the file mentioned in the log because the file never belonged to this repo. A solution is to split commits to the different repositories.
This worked for me:
Based on this great article: http://www.speirs.org/blog/2009/5/11/understanding-git-submodules.html