Add package from git on specific branch or commit

Unity 2021.3 manual says that it’s possible to target a specific branch in a git repository when adding a package from Git:

Targeting a specific revision

However, all the examples are on the HTTPS protocol. When I try to target a specific branch or commit with the GIT: protocol, I get a ‘Version range is invalid’ error in the console.

Is there no way to reference a private repo on a specific branch or commit?

What is the URL you try to import? The format suffices, eg use placeholders for bits you don’t want to share.

I tend to think that importing packages from private repos is not supported because Package Manager does not offer ways to specify user credentials.

I believe this is one of the cases where a custom “scoped registry” needs to be used. Meaning: you’ll be running your own upm registry serving your own packages. I haven’t done this myself, but I think that registry would be running on a machine where you can manually or automatically sync changes from github to a package folder that the registry would “serve”. So it won’t be automatically/instantaneously make any changes available.

If however you work alone or in a small team I would simply make everyone pull that repository locally, preferably to a location that is the same drive & path on every system, and then import that package “from disk”.
I believe you can also manually update the manifest.json to point to a package using a relative path, so that you don’t have to rely on the same drive/path for every machine but rather have the package installed side-by-side with the project.

Of course, if you submit a change that relies on a submitted change in the package, everyone else needs to pull the latest changes for both repositories. That is probably the biggest drawback of this approach, hence I wouldn’t recommend it for teams close to and upwards of 10 devs.

Ok sorry, I didn’t quite know the correct terminology to use.

I’m using the link from the “Code → Clone SSH” menu on GitHub, which the Unity manual refers to as “SCP-shorthand” (ie git@github.com:company/repo.git).
This works fine when I just want to add a package from the tip of the default branch. But if I want to specify a branch, tag or commit, I would expect being able to use the hashtag notation, but the documentation is not clear whether this is supported-- so my guess is, it isn’t. Since I need authentication for the repo, there are no other options as user/password auth is disabled.

ATM my only hope is to import the default branch and then manually edit the packages-lock.json file to a specific commit.

Hi @andersemil ,

This is a known limitation with the SCP shorthand syntax which does not accept the Package Manager extensions (namely, specifying a path and/or a revision). There is a workaround for this limitation until we fix this by converting the SCP “URL” into a valid SSH URL in your “manifest.json” file. After that, you can use the path and/or revision syntax (for instance, specifying your feature branch). Please refer to this post explaining how to do that.