# Github - How to clone/install specific branch?

**URL:** <https://discourse.julialang.org/t/github-how-to-clone-install-specific-branch/23572>\
**Category:** New to Julia\
**Tags:** github\
**Created:** [April 26, 2019, 5:28pm UTC](https://discourse.julialang.org/t/github-how-to-clone-install-specific-branch/23572 "2019-04-26T17:28:43Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [April 26, 2019, 5:28pm UTC](https://discourse.julialang.org/t/github-how-to-clone-install-specific-branch/23572/1 "2019-04-26T17:28:44Z")

</div>

Hey guys!

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

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

```

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

```julia
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

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [April 26, 2019, 6:37pm UTC](https://discourse.julialang.org/t/github-how-to-clone-install-specific-branch/23572/2 "2019-04-26T18:37:00Z")

</div>

Try

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

```

can’t test it right now.

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [April 26, 2019, 6:58pm UTC](https://discourse.julialang.org/t/github-how-to-clone-install-specific-branch/23572/3 "2019-04-26T18:58:16Z")

</div>

It works, thanks!

---

<div class="post-metadata">

**Author:** ![Xing\_Shi\_Cai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xing_shi_cai/32/14128_2.png) [@Xing\_Shi\_Cai](https://discourse.julialang.org/u/Xing_Shi_Cai)\
**Post date:** [October 13, 2022, 4:26pm UTC](https://discourse.julialang.org/t/github-how-to-clone-install-specific-branch/23572/4 "2022-10-13T16:26:34Z")

</div>

What if I want to use `git` instead of `https`?

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [October 13, 2022, 7:23pm UTC](https://discourse.julialang.org/t/github-how-to-clone-install-specific-branch/23572/5 "2022-10-13T19:23:33Z")

</div>

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

> **[Improving Git protocol security on GitHub](https://github.blog/2021-09-01-improving-git-protocol-security-github/#no-more-unauthenticated-git)**
>
> We’re changing which keys are supported in SSH and removing unencrypted Git protocol. If you’re an SSH user, read on for the details and timeline.

?

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [October 13, 2022, 8:42pm UTC](https://discourse.julialang.org/t/github-how-to-clone-install-specific-branch/23572/6 "2022-10-13T20:42:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Xing\_Shi\_Cai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xing_shi_cai/32/14128_2.png) [@Xing\_Shi\_Cai](https://discourse.julialang.org/u/Xing_Shi_Cai)\
**Post date:** [October 14, 2022, 4:13am UTC](https://discourse.julialang.org/t/github-how-to-clone-install-specific-branch/23572/7 "2022-10-14T04:13:14Z")

</div>

Yes. That’s what I meant.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [October 14, 2022, 10:01am UTC](https://discourse.julialang.org/t/github-how-to-clone-install-specific-branch/23572/8 "2022-10-14T10:01:27Z")

</div>

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

- [SSH host verification fails when IP changes (git succeeds) · Issue #2334 · JuliaLang/Pkg.jl · GitHub](https://github.com/JuliaLang/Pkg.jl/issues/2334)

- [Generating a new SSH key and adding it to the ssh-agent - GitHub Docs](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent)

First attempt:

```julia
(@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
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:

```julia
 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:

```julia
(@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:

```julia
(@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 😉

---

<div class="post-metadata">

**Author:** ![RoyW](https://avatars.discourse-cdn.com/v4/letter/r/e9bcb4/32.png) [@RoyW](https://discourse.julialang.org/u/RoyW)\
**Post date:** [October 28, 2022, 6:58am UTC](https://discourse.julialang.org/t/github-how-to-clone-install-specific-branch/23572/9 "2022-10-28T06:58:08Z")

</div>

See [Julia v1.6.0-rc1 and SSH host verification](https://github.com/JuliaLang/Pkg.jl/issues/2428#issuecomment-809559152) for another work around, but keep in mind of the warning by **[StefanKarpinski](https://github.com/StefanKarpinski)**.

---

<div class="post-metadata">

**Author:** ![Tortar](https://avatars.discourse-cdn.com/v4/letter/t/6bbea6/32.png) [@Tortar](https://discourse.julialang.org/u/Tortar)\
**Post date:** [March 2, 2023, 1:15am UTC](https://discourse.julialang.org/t/github-how-to-clone-install-specific-branch/23572/10 "2023-03-02T01:15:32Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![brunompacheco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brunompacheco/32/209375_2.png) [@brunompacheco](https://discourse.julialang.org/u/brunompacheco)\
**Post date:** [February 27, 2025, 8:43pm UTC](https://discourse.julialang.org/t/github-how-to-clone-install-specific-branch/23572/11 "2025-02-27T20:43:59Z")

</div>

Same here. Flagged solution doesn’t work, but the one @Tortar provided does.

---

<div class="post-metadata">

**Author:** ![GHTaarn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ghtaarn/32/216007_2.png) [@GHTaarn](https://discourse.julialang.org/u/GHTaarn)\
**Post date:** [February 28, 2025, 8:49am UTC](https://discourse.julialang.org/t/github-how-to-clone-install-specific-branch/23572/12 "2025-02-28T08:49:11Z")

</div>

Both methods should work. What is not mentioned in the flagged solution is that it must be done from the REPLs [package mode](https://docs.julialang.org/en/v1/stdlib/REPL/#Pkg-mode) which is activated by pressing `]` as the first character on a REPL line.

---

<div class="post-metadata">

**Author:** ![brunompacheco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brunompacheco/32/209375_2.png) [@brunompacheco](https://discourse.julialang.org/u/brunompacheco)\
**Post date:** [February 28, 2025, 9:48pm UTC](https://discourse.julialang.org/t/github-how-to-clone-install-specific-branch/23572/13 "2025-02-28T21:48:21Z")

</div>

Oh, my bad! You are correct, the flagged solution indeed works. The problem I had with it is that `add` does not add branch information in the `Project.toml` (nor the repo’s url). So if you try to instantiate from that, Pkg will install the registered version (or raise an error, if the package is not registered). But then, neither of the solutions solve this problem.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [February 28, 2025, 10:00pm UTC](https://discourse.julialang.org/t/github-how-to-clone-install-specific-branch/23572/14 "2025-02-28T22:00:01Z")

</div>

It does add the branch information in the Manifest though, and you can instantiate from that.

```julia
(test) pkg> add Example#master
    Updating git-repo `https://github.com/JuliaLang/Example.jl.git`
   Resolving package versions...
    Updating `/tmp/test/Project.toml`
  [7876af07] + Example v0.5.5 `https://github.com/JuliaLang/Example.jl.git#master`
    Updating `/tmp/test/Manifest.toml`
  [7876af07] + Example v0.5.5 `https://github.com/JuliaLang/Example.jl.git#master`

julia> foreach(println, readlines("Manifest.toml"))
# This file is machine-generated - editing it directly is not advised

julia_version = "1.11.2"
manifest_format = "2.0"
project_hash = "2ca1c6c58cb30e79e021fb54e5626c96d05d5fdc"

[[deps.Example]]
git-tree-sha1 = "84ec67045e0af90908e775e4d7a3782b9f27e98a"
repo-rev = "master"
repo-url = "https://github.com/JuliaLang/Example.jl.git"
uuid = "7876af07-990d-54b4-ab0e-23690620f79a"
version = "0.5.5"

```
