Using a specific commit or branch when `using mypkg`

I have a simulation model that is in the form of a Julia package, i.e. I can do using mypkg and call the function run(). This works fine, but I have several scientific projects that use this model and each project is slightly different in terms of the dynamics or algorithm changes.

My master branch that is the most updated model naturally. I have dev'ed this in my local dev machine. But lets say I am working on a project which branched off the master about a month ago. My current workflow is to manually git checkout commitid (thus going to the old cold) then call using mypkg which also then triggers recompilation and so on.

I am wondering if this can be automated slightly. Is it possible to do something like using mypkg#commitid so that it pulls in that specific commit id (or branch)? This way I won’t have to keep checking out different commits and switching from master back and forth.

Furthermore, this would really help with scientific reproducibility. (I realize that anyone can actually do add mypkg#commitid but that dosn’t help me). For example, I can just tell someone to add my package add mypkg, and pass them a “script” file that says using mypkg#commitid so that the end user dosn’t have to worry about manually add'ing the correct branch.

If you run each project in a different session of Julia, the best way to achieve this is creating a different environment for each project. In the environment of Project A, ]add MyPkg#branch_a, etc. Then just activate the corresponding environment for each project, and go with using MyPkg.

Ah, I see. I think I can maybe use DrWatson to dynamically create these environments.

I saw you added this commentary while I was still answering. :slight_smile: Instead of passing only the script file, always share the script + the files of the environment (Project.toml and Manifest.toml).