I have a project that uses modules. One of the modules that I need to use is inside another repository. In the future, I will connect that module into my project using mavenCentral, but not now.
I want to have my MODULE from another repository inside my PROJECT without adding the MODULE into my PROJECT GIT. And I should be able to switch between git repos and commit the changes into their corresponding repositories.
So far I did this:
-- added MODULE origin inside PROJECT like so.
git remote add MODULE [module URL in Github]
git fetch MODULE
after the above steps, when I do git remote -v it is displaying two remotes. One for PROJECT (origin) and one for MODULE.
After these steps, I am not sure what to do next in order to achieve my objective. Is it even possible?
I tried git merge MODULE/master --allow-unrelated-histories but it is adding my MODULE code into my PROJECT which I don't want.
Could someone point me in the right direction?
Thanks.
It would be easier to use git submodule for that kind of use.
Your parent repository would keep a reference on your MODULE repository in a MODULE subfolder, but any change done on that subfolder can be pushed directly to the remote MODULE repository.
cd /path/to/repo
git submodule add [module URL]
cd module
# work on module, add, push, commit
cd ..
git add module
git commit -m "reference new module state"
The OP amira confirms in the comments:
Worked like a charm.
In the settings.gradle folder, don't forget to include the module and provide a path as described in "Android Studio - How to make modules inside a subdirectory?".
Related
I am trying to convert my existing application into a number of modules.
Is it possible for me to have each module pointing to a git repository so I can grant access to people accordingly?
So my structure is like this
APP --> Git 1
Module 1 --> Git 2
Module 2 --> Git 3
...
Is this possible for me to do with an android studio project?
The idea is for me to be able to give different developers different modules and not let them access other modules. I have never used git this extensively so dont really know how this works
Please help
Nikhil
Yes, Android studio supports multiple git repos.
you will have something like:
Repositories:
Repo 1 -> master
Repo 2 -> feature/branch-name
in AS Select VCS, VCS popup and import or check out repo. Or you can create new repo in your folder and and independently in subfolders.
I was using a project as module dependency in Android Studio. I no longer now need it. So I removed the dependency from build.gradle file and then committed and pushed it. When i take a fresh check out using git in Android Studio, i am able to see that module, even though that is not being used by my project. If i check on the git site, the folder is still there. I think i need to delete it from the cache of the git which maintain the history of this. But I do not know the commands to run in the Android studio terminal to completely remove it from git respository.
Project Structure
Project
|
-app
-build.gradle(removed dependency of module 1)
-Module1
-Module2
-module3
-settings.gradle(removed module1)
Want to remove module1 from the git. Please let me know the commands.
The problem is the Android Project which I have has in all 3 modules viz. 1 main & other supporting modules.
Currently I pushed the whole project to BitBucket which includes the modules too, but I'm confused if I should just push modules in different repos & not in a single repo like I have did.
If different repos is the best way to go head, then how should I link all the 3 repos to represent as a single project.
If it is one Android project then you should probably use submodules. Read this tutorial to know more about how to create submodules:
https://git-scm.com/book/en/v2/Git-Tools-Submodules
Then you can use
git submodule foreach git pull
To pull all submodules recursively or
git pull --recurse-submodules
I recommend you to create another Bitbucket repos for each supporting module then you could use git submodules to link them with your main project or just upload the artifacts to a maven repo like jcenter, sonatype or bintray, then you can compile they as dependencies in build.gradle. I prefer the second option.
Git submodule:
http://blogs.atlassian.com/2013/03/git-submodules-workflows-tips/
I cloned an android project from github. I made changes after cloning and pushed it to the main repository from android studio. Everything worked fine but when I add an external library in my project I can't push it. I think its a sub module. Could anyone tell me how to push external library as a sub module from android studio?
After searching internet I found a simple way to do it. To add a sub-module we need to run this command
git submodule add LIBRARY_URL
and to init the sub module locally
git submodule update --init --recursive
If it is a submodule, you should be able to list the gitlink entry, special mode 160000
$ git ls-tree HEAD mysubmodule
160000 commit c0f065504bb0e8cfa2b107e975bb9dc5a34b0398 mysubmodule
It should also be recorded in your main repo/.gitmodules file.
In that case, all you need to do is add and commit that entry, and push it.
If it is not, then remove that folder, and add it again as a submodule through command-line (instead of Eclipse/Egit)
git submodule add /url/of/library/repo mysubmodule
git add mysubmodule # no trailing / here)
git commit -m "Add a submodule"
git push toAndroidRemoteRepo
I have an Android application under development which makes use of a separate library project of my own. These two projects are stored in separate Git repositories. The application project references the library project by means of the .gitmodules file.
I'm now trying to work on both of these projects together (the application and the library) on a new machine. I cloned the application project, which resulted also in the library project being automatically cloned into my ~/git/ directory as well. So far so good.
I notice also that in Eclipse Package Explorer, the library project root has a commit hash within brackets (e.g. [MyLibraryName 0123ABC]). This presumably means that the library clone is from a certain commit point, and I understand that I could update this (i.e pull in the latest commits for this library) using git submodule foreach git pull.
Question is, what is the best way for me to continue separately developing the library project now? I tried to modify a file and stage it, but when using Team->commit, the dialogue didn't list the modified file. I assume this might be something to do with it being a submodule, pointing at a particular commit.
Should I clone my library project again, completely separately into a different subdirectory, and import as a separate project into Eclipse in order for me to do work on that library?
Having read various other SO questions, it seems apparent that there's no elegant solution for this. The steps I eventually took to solve this are:
Assuming not done so already, clone the application repository that makes use of submodules. Import all projects into Eclipse workspace, including the submodule repository (or repositories). Note that the submodule repository is a repository within the main application repository, and it's not on a particular branch; it's a reference to a particular commit (detached head).
In the Package Explorer, rename the submodule project that was imported. I gave it a name that relates to the application repo it's inside of. For instance, for an application project called ABCD, rename it from SomeLibrary to SomeLibrary_ABCD.
Next, clone the library separately from its own Git repository. Now, the point of renaming the submodule project is that it's now possible to import the Eclipse project from the standalone clone of the library repository, without Eclipse giving the "Some or all projects can not be imported because they already exist in the workspace" error.
Having done this, we have SomeLibrary_ABCD project which is not on a branch but points to a particular commit, and is a submodule of project ABCD. That submodule is updated using git submodule foreach git pull. Then, we have project SomeLibrary, which is on a branch (e.g. master).
My planned workflow is to locally switch the application project to point at my 'standalone' project of the library instead of the submodule version when I want to do development on the library. I then commit changes to SomeLibrary.
Any better suggestions than this (or corrections to anything I've stated) would be appreciated - but for now this is my own answer to the problem.