There is a package that I am developing (GitHub - SciML/Catalyst.jl: Chemical reaction network and systems biology interface for scientific machine learning (SciML). High performance, GPU-parallelized, and O(1) solvers in open source software.). Locally, I have a couple of branches of it. I also have an environment where I would like to use a specific of these branches (one which is not pushed onto GitHub). is there a way to do this?
Previously I just did
]dev Catalyst
however, that gives me the active branch. If I am working with two branches in parallel (one which I want to use for this project, and one where I am preparing a new PR) this is not possible using this approach.
The dev
command should give you the current code in the directory and no matter whether it is committed to git
or not. You can still access the code in other branches by using add
with the full path to the repository and appending #branchname
on the end of the path even if the branch is not the current HEAD, e.g. :
] add ~/code/MyPackage.jl#devbranch2
If this is not enough, then you could either clone your local working copy or make a recursive copy of it (in Linux this is done with cp -a
). But only do this if you have to, as it can get quite confusing to be working on two copies of the same code.
3 Likes
This will perform a local git pull to obtain the code from the repo ~/code/MyPackage.jl
. The code changes in the latter folder will not be automatically tracked. Any changes need to be committed first, and then in the virtual environment where you ran Pkg.add
, you need to run Pkg.update
to obtain the new code. If instead, you want to automatically track code changes in ~/code/MyPackage.jl
, including any committed or uncommitted changes (or even without a git repo in the folder at all), you need to run
] dev ~/code/MyPackage.jl
2 Likes
So if I want to get branch required_branch
of package Catalyst, I should do
] add .../.julia/dev/Catalyst#required_branch
And then I can switch to another active Catalyst branch, but required_branch
should be preserved for that environment? Next, version of
]dev Catalyst
will only ever give me there currently active code in “…/.julia/dev/Catalyst”, whether it is committed or not?
dev
is not git-aware like add
is, it simply uses whatever code is in the local folder. So if you want to dev two different branches, you’ll need to make two separate clones of the repo into different folders, check out the branches you want to dev in each one, then do
pkg> dev /path/to/repo
1 Like
Thanks guys, this was really helpful. Think I understand how to (and not how to) do it now!
1 Like
I haven’t used the worktree feature myself, but this sounds like a good usecase for git worktrees.
3 Likes