# Loading a package from a fork

**URL:** <https://discourse.julialang.org/t/loading-a-package-from-a-fork/52017>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [December 18, 2020, 1:06am UTC](https://discourse.julialang.org/t/loading-a-package-from-a-fork/52017 "2020-12-18T01:06:41Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![compleat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compleat/32/8958_2.png) [@compleat](https://discourse.julialang.org/u/compleat)\
**Post date:** [December 18, 2020, 1:06am UTC](https://discourse.julialang.org/t/loading-a-package-from-a-fork/52017/1 "2020-12-18T01:06:41Z")

</div>

Apologies but I can’t seem to find clear documentation on this.  
[and the little I did find didn’t work]

I have created a fork from a package on github, and before tinkering with it, I want to see how to just load the package (as is) from the fork (as a test).

Most of the documentation I found seems to refer to Pkg.clone(), but I saw elsewhere that this seems to be deprecated and subsumed into Pkg.add().  
(First question) Is this correct?

Assuming the answer to the above is ‘yes’, I tried to add Pkg.add() with my forked url path on github but it didn’t work.

(Second question) Do I need to do something first to my forked package on github after having created it using ‘fork’ in order to be able to load it with ‘add’?

(third question) There was reference somewhere to using the ‘#’ to refer to a forked version of a package. How does this work?

Sorry for such basic questions, but thanks for any help.

---

<div class="post-metadata">

**Author:** ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)\
**Post date:** [December 18, 2020, 1:18am UTC](https://discourse.julialang.org/t/loading-a-package-from-a-fork/52017/2 "2020-12-18T01:18:50Z")

</div>

Try doing:

```julia
]
add <url>

```

The `]' goes into the package manager and `add ` adds the package. Granted Pkg.add() should be doing the same thing I believe. So my question would be how did Pkg.add() fail?

---

<div class="post-metadata">

**Author:** ![Pbellive](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbellive/32/3604_2.png) [@Pbellive](https://discourse.julialang.org/u/Pbellive)\
**Post date:** [December 18, 2020, 1:36am UTC](https://discourse.julialang.org/t/loading-a-package-from-a-fork/52017/3 "2020-12-18T01:36:24Z")

</div>

If you want to add a package from a url using the `Pkg` api (rather than the package manager repl mode as @pixel27 suggested) you need to do

```julia
Pkg.add(url="url-goes-here")

```

That will work with a git ssh repo addresses. The `Pkg.add(pkg_name::String)` method only works for registered packages that you can refer to by name, i.e. `Pkg.add("DataFrames")`.

FWIW, if you’re planning to play with a fork of a package, I would just do

```julia
Pkg.develop(url="address of your fork repo")

```

That will clone your fork of the package into your julia package development directory. If you then import the package (i.e. `using ForkedPackage`) it will load the version you’ve just cloned. If you want to go back to a registered version of the package just do `Pkg.free("ForkedPackage")` or run

```julia
free ForkedPackage

```

from the package manager repl mode. Then the next time you want to switch back to your local version of the package just do

```julia
dev ForkedPackage

```

and the package manager will switch back to the version of the package sitting in your package development directory.

Finally, by default your julia package development directory is ~/.julia/dev but you can set it to be somewhere else using the environment variable JULIA\_PKG\_DEVDIR. For more info see the developing package section of the package manager docs: [3. Managing Packages · Pkg.jl](https://julialang.github.io/Pkg.jl/v1/managing-packages/#developing)

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [December 18, 2020, 5:46am UTC](https://discourse.julialang.org/t/loading-a-package-from-a-fork/52017/4 "2020-12-18T05:46:22Z")

</div>

Developing an existing package is explained here:

> [@How to contribute to existing package](https://discourse.julialang.org/t/how-to-contribute-to-existing-package/32749):
>
> How to develop existing packages? If I want to develop Example.jl, should I use pkg and pkg\> develop --local Example or fork the repo and then clone to desktop? If so, how do I load my local copy of package to Julia? How do I run tests? Right now I think I would do the following: Fork the repo on GitHub. Clone the forked repo to my desktop. Somehow make my Julia REPL recognize the clone of the forked repo on desktop as the correct package to run. Code in Juno and test in REPL. Push to my fo…

The julia package manager docs (your third question) is here:  
[https://julialang.github.io/Pkg.jl/v1/managing-packages/](https://julialang.github.io/Pkg.jl/v1/managing-packages/)  
The ‘#’ symbol is used more to check out a specific branch. I think this can include other people’s PR (pull request) branches, but that’s different than you creating a PR branch (which your post above seems to be about)

---

<div class="post-metadata">

**Author:** ![compleat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compleat/32/8958_2.png) [@compleat](https://discourse.julialang.org/u/compleat)\
**Post date:** [December 18, 2020, 9:44am UTC](https://discourse.julialang.org/t/loading-a-package-from-a-fork/52017/5 "2020-12-18T09:44:26Z")

</div>

Thanks so much all!

Some of the above I had tried and had not worked, but I will try your other suggestions first before trying to troubleshoot the ones that didn’t work.  
If I do need to troubleshoot latter, I will post the error(s) I got.  
Thanks again.

\*\*\* I tried again and the error I keep getting is ‘cross-host redirect not allowed’

---

<div class="post-metadata">

**Author:** ![compleat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compleat/32/8958_2.png) [@compleat](https://discourse.julialang.org/u/compleat)\
**Post date:** [December 18, 2020, 1:00pm UTC](https://discourse.julialang.org/t/loading-a-package-from-a-fork/52017/6 "2020-12-18T13:00:51Z")

</div>

Whenever I tri the suggestions above, I get the error

```julia
ERROR: failed to clone from https://www.github.com/compleathorseplayer/Pluto.jl, error: GitError(Code:ERROR, Class:Net, cross host redirect not allowed)

```

---

<div class="post-metadata">

**Author:** ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)\
**Post date:** [December 18, 2020, 1:03pm UTC](https://discourse.julialang.org/t/loading-a-package-from-a-fork/52017/7 "2020-12-18T13:03:48Z")

</div>

Try “[https://github.com/compleathorseplayer/Pluto.jl](https://github.com/compleathorseplayer/Pluto.jl)” without the www.

---

<div class="post-metadata">

**Author:** ![compleat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compleat/32/8958_2.png) [@compleat](https://discourse.julialang.org/u/compleat)\
**Post date:** [December 18, 2020, 1:06pm UTC](https://discourse.julialang.org/t/loading-a-package-from-a-fork/52017/8 "2020-12-18T13:06:48Z")

</div>

Thank you! That worked!

[I did get some unsatisfiable requirements, which is a different issue (fixed)]

---

<div class="post-metadata">

**Author:** ![compleat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compleat/32/8958_2.png) [@compleat](https://discourse.julialang.org/u/compleat)\
**Post date:** [December 18, 2020, 1:37pm UTC](https://discourse.julialang.org/t/loading-a-package-from-a-fork/52017/9 "2020-12-18T13:37:25Z")

</div>

Just one last thing (nearly there!)

What if the version I want is actually …/\<Pkg name\>.jl/tree/\<branch name\>

Should I have forked the whole Package and refer to the branch on import,  
or should I just fork the branch and it will be assumed when I import?  
Thanks again!

---

<div class="post-metadata">

**Author:** ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)\
**Post date:** [December 18, 2020, 1:46pm UTC](https://discourse.julialang.org/t/loading-a-package-from-a-fork/52017/10 "2020-12-18T13:46:52Z")

</div>

Check:

```julia
?Pkg.add

```

Some of the examples it shows:

```julia
  Pkg.add("Example") # Add a package from registry
  Pkg.add("Example"; preserve=Pkg.PRESERVE_ALL) # Add the `Example` package and preserve existing dependencies
  Pkg.add(name="Example", version="0.3") # Specify version; latest release in the 0.3 series
  Pkg.add(name="Example", version="0.3.1") # Specify version; exact release
  Pkg.add(url="https://github.com/JuliaLang/Example.jl", rev="master") # From url to remote gitrepo
  Pkg.add(url="/remote/mycompany/juliapackages/OurPackage") # From path to local gitrepo
  Pkg.add(url="https://github.com/Company/MonoRepo", subdir="juliapkgs/Package.jl)") # With subdir

```

---

<div class="post-metadata">

**Author:** ![compleat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compleat/32/8958_2.png) [@compleat](https://discourse.julialang.org/u/compleat)\
**Post date:** [December 18, 2020, 3:03pm UTC](https://discourse.julialang.org/t/loading-a-package-from-a-fork/52017/11 "2020-12-18T15:03:16Z")

</div>

Yes, that helped immensely. It is all working now.

Thank you so much!
