Update:
I think I may have found one possible solution for this question: git worktree
. I'll have to investigate its exact workings a bit more, because I'm not entirely sure yet if it can do what I want (particularly automatically keeping synced). But if it's viable, I'll answer my own question with my own solution.
I might be going about this in an unorthodox way and that's why I'd like to get some input on alternative ideas.
I have created a Java Promise library, that is in ongoing development. I've included this library into an Android app that I am currently developing as well. At this point only my Promise library is version controlled with Git.
I only develop for myself, locally, so there's no worries about other people's commits or remote repositories.
Here's the basic local structure:
- /Library/Promise/.git
- /App/MyApp/
Right now, when I want do some work on the Promise library, by checking out, say, the "develop" branch, this change is immediately reflected in MyApp's code as well1. I'd like to prevent this from happening. I'd like to only include a version of my Promise library that I am currently happy with.
For instance, only include:
- the master branch
- a tagged commit
- etc.
In the meanwhile I've actually found a way to achieve what I want, when a repository is hosted on Github. But I'd like to achieve this exact same thing with a local git repository.
Is there a convenient way to only include a snapshot of the library's Git code, without having to make a copy of the library? Or is it typically not custom to directly include a Git repository into another project, like this?
Preferably, I'd like to stay away from advanced dependency repositories, like Maven and what have you, for now, as that's a bit too much much hassle for me, at the moment. I'm hoping there are some less involved alternatives for this conundrum.
To address @candied_orange's comment:
I develop for Android using Android Studio (on Ubuntu). The way I link my library to my app is as follows:
settings.gradle:
rootProject.name='MyApp' include ':app', ':codifier-promise' project(':codifier-promise').projectDir = new File("../Library/Promise/promise")
build.gradle (Module: app):
... dependencies { ... implementation project(':codifier-promise') }
In other words, I link to the library directory, in stead of hard copying the code into my app. I like this approach, because, in principle, it allows me to always have the link to the latest version, in stead of having to copy it in each time I changed something.
However, as a consequence of this, when I (temporarily) check out another Git branch of my library (that I don't see fit for production yet), this automatically also is the library "version" that will show up in my app's code.
My aim is to only link to a particular "version" of my library, that I am happy with. Preferably without having to link to an external server like Github, etc., even though my Promise repository is currently hosted on Github as well.
Because, in the meanwhile I've actually found a way to achieve what I want with code hosted on Github. But, I'd just like to know if I can achieve something similar locally as well, for when I decide to include a local library that I don't want to host on an external server.
mvn install
to install the specific version in your local cache, and then use that version in your app.mvn install
and use it. (And then go back to a snapshot version, so that you don't overwrite that release by accident.) The only thing to watch out for is, that the version will disappear if you ever delete your local repository cache or move to a different machine.