Github - How to clone/install specific branch?

Hey guys!

I started using Github for my package (GitHub - AhmedSalih3d/PostSPH.jl: Easing the process of post-processing simulations done in DualSPHysics) and I have two different branches, “master” and “dev”. If I do the command to install the package like this:

add https://github.com/AhmedSalih3d/PostSPH.jl

It works, but say I want a specific branch ie. “dev”:

add https://github.com/AhmedSalih3d/PostSPH.jl/tree/dev
   Cloning git-repo `https://github.com/AhmedSalih3d/PostSPH.jl/tree/dev`
ERROR: failed to clone from https://github.com/AhmedSalih3d/PostSPH.jl/tree/dev, error: GitError(Code:ERROR, Class:Net, request failed with status code: 404)

I assume the 404 error is “not found”, but how do I then do?

Kind regards

1 Like

Try

add https://github.com/AhmedSalih3d/PostSPH.jl#dev

can’t test it right now.

7 Likes

It works, thanks!

What if I want to use git instead of https?

I don’t know but perhaps it’s obsolete:

?

I would suspect they mean they want to use ssh rather than https, as in git@github.org:user/repo#branch

1 Like

Yes. That’s what I meant.

I played it through with the following outcome.
Sources to follow on how to make it work:

First attempt:

(@v1.8) pkg> add "git@github.com:oheil/NormalizeQuantiles.jl.git"
     Cloning git-repo `git@github.com:oheil/NormalizeQuantiles.jl.git`
SSH host verification: the identity of the server `github.com:22` does not 
match its known hosts record. Someone could be trying to man-in-the-middle
your connection. It is also possible that the server has changed its key, in
which case you should check with the server administrator and if they
confirm that the key has been changed, update your known hosts file.
ERROR: failed to clone from git@github.com:oheil/NormalizeQuantiles.jl.git, 
error: GitError(Code:ERROR, Class:Net, user cancelled hostkey check)

I had to set a environment variable before running Julia REPL, this maybe not the case for everyone:

julia> ENV["JULIA_SSH_NO_VERIFY_HOSTS"]
"github.com"

E.g. for windows this can be done in the CMD where Julia REPL is started later:

 set JULIA_NO_VERIFY_HOSTS="github.com"

I am on Julia 1.8.2 perhaps some day in future this is not needed anymore.

Now setting up ssh keys as described in above github documentation.

I did the key generation in a Linux shell. As I want to use it on Windows, I had to convert it into ppk format, using “PuTTY Key Generator” (menu Conversions) and saving it as .ppk.
The PuTTY version of ssh-agent is Pageant, where I imported the .ppk key.

Now next attempt:

(@v1.8) pkg> add "git@github.com:oheil/NormalizeQuantiles.jl.git"
     Cloning git-repo `git@github.com:oheil/NormalizeQuantiles.jl.git`
    Updating git-repo `git@github.com:oheil/NormalizeQuantiles.jl.git`
    Updating registry at `C:\Users\oheil\.julia\registries\General`
    Updating git-repo `https://github.com/JuliaRegistries/General.git`
  1 dependency successfully precompiled in 5 seconds. 335 already precompiled.

To get to a specific tagged version of this project you can do now:

(@v1.8) pkg> add NormalizeQuantiles#offset-arrays
    Updating git-repo `git@github.com:oheil/NormalizeQuantiles.jl.git`
   Resolving package versions...
    Updating `C:\Users\oheil\.julia\environments\v1.8\Project.toml`
  [d366530f] ~ NormalizeQuantiles v1.2.2 `git@github.com:oheil/NormalizeQuantiles.jl.git#master` ⇒ v1.0.0 `git@github.com:oheil/NormalizeQuantiles.jl.git#offset-arrays`
    Updating `C:\Users\oheil\.julia\environments\v1.8\Manifest.toml`
  [d366530f] ~ NormalizeQuantiles v1.2.2 `git@github.com:oheil/NormalizeQuantiles.jl.git#master` ⇒ v1.0.0 `git@github.com:oheil/NormalizeQuantiles.jl.git#offset-arrays`
Precompiling project...
  1 dependency successfully precompiled in 3 seconds. 335 already precompiled.

Well, successful, except not as convenient as the https protocol :wink:

1 Like

See Julia v1.6.0-rc1 and SSH host verification for another work around, but keep in mind of the warning by StefanKarpinski.

1 Like

Actually the accepted solution didn’t work for me it strangely always installs main, but this instead works

Pkg.add(url = "https://github.com/orgname/reponame.git", rev = "branch_name")
1 Like