Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Flutter and app store releases

flutter pub get cannot clone or read a package that comes from a Git repository

Your error

Git error. Command: `git clone --mirror -- https://github.com/my-org/my_package.git3 more lines it can show

Fix it fast

Most common cause, 1 of 4

Git is not installed, or pub cannot see it on PATH

Install Git, or add the folder that holds git.exe to PATH, then open a new terminal so the changed PATH applies.

Fix
git --version
flutter pub get
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Git error. Command: git clone --mirror during flutter pub get (Flutter 3.50, Dart 3.14) means pub could not clone or read a git dependency. Pub runs git clone, so the pubspec URL must clone in the same shell. Install Git on PATH, give the machine a key for private repos, fix the ref, or add a path for subfolder packages.

  • Applies to Flutter 3.50 stable, Dart 3.14, Git 2.56
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Clone the URL from pubspec.yaml by hand, in the same terminal and user account that runs flutter pub get. Pub calls git clone as a subprocess, so if this command fails, pub fails the same way, and Git's own message is clearer.

Run this first
git clone https://github.com/my-org/my_package.git /tmp/pub-clone-test

Then find the line you see in this list and open its fix:

  1. 1Git is not installed, or pub cannot see it on PATHCannot find a Git executable. Please ensure Git is correctly installed.
  2. 2The repository is private and this machine has no accessThe Git error's stderr shows a login prompt, an authentication failure or a publickey rejection; the clone works on another machine
  3. 3The ref in pubspec.yaml does not exist in the repositoryCould not find git ref '<name>'
  4. 4The package sits in a subfolder of the repositoryCould not find a file named "pubspec.yaml" in <repository> <commit>

What does the error look like?

  • Git error. Command: `git clone --mirror -- https://github.com/my-org/my_package.git
  • Cannot find a Git executable.
  • Could not find git ref 'v2.0.0'
  • Could not find a file named "pubspec.yaml" in

Cause 1 of 4

Git is not installed, or pub cannot see it on PATH

You seeCannot find a Git executable. Please ensure Git is correctly installed.

Check

Cannot find a Git executable means pub found no usable git command on PATH, so it cannot clone the dependency at all. Pub looks for git on PATH. On Windows it only accepts git.exe, and it says so when it finds just a git.bat or git.cmd wrapper. Ask the shell which git it would run.

Check
git --version
which git        # macOS / Linux
where git        # Windows

Fix

Install Git, or add the folder that holds git.exe to PATH, then open a new terminal so the changed PATH applies. Pub warns when Git is older than 2.14, so upgrade a very old install as well.

Fix
git --version
flutter pub get

Verify

flutter pub get gets past the git dependency and writes it to pubspec.lock.

Verify
grep -n -A4 "my_package:" pubspec.lock

Confirmed by github.com

Did this fix it?

Cause 2 of 4

The repository is private and this machine has no access

You seeThe Git error's stderr shows a login prompt, an authentication failure or a publickey rejection; the clone works on another machine

Check

Git error. Command: git clone --mirror with an authentication message in stderr means the repository is private and this machine has no credentials for it. Private repositories need either an SSH key pair or an HTTPS access key on the machine that runs pub. For GitHub over SSH, test the key directly.

Check
ssh -T git@github.com

Fix

Use the SSH form of the URL with a key that the host accepts, or set up an HTTPS token through your Git credential setup. In CI, add the deploy key or token to the job before flutter pub get runs.

Fix
dependencies:
  my_package:
    git:
      url: git@github.com:my-org/my_package.git

Verify

ssh -T git@github.com greets you by user name, and pub get then clones the repository.

Verify
flutter pub get

Confirmed by dart.dev

Did this fix it?

Cause 3 of 4

The ref in pubspec.yaml does not exist in the repository

You seeCould not find git ref '<name>'

Check

Could not find git ref means the branch, tag or commit named in ref is not in the cloned repository. A ref can be any name Git uses to point at a commit: a branch, a tag or a commit hash. A renamed branch, a deleted tag or a typo makes the lookup fail. List what the remote really has.

Check
git ls-remote https://github.com/my-org/my_package.git
git ls-remote --tags https://github.com/my-org/my_package.git

Fix

Put a name from that list into ref. A full commit hash never moves, so the build stays the same when someone pushes to the branch.

Fix
dependencies:
  my_package:
    git:
      url: https://github.com/my-org/my_package.git
      ref: v2.1.0

Verify

Run pub get again; pubspec.lock now records the commit that the ref points to.

Verify
flutter pub get && grep -n -A6 "my_package:" pubspec.lock

Confirmed by dart.dev

Did this fix it?

Cause 4 of 4

The package sits in a subfolder of the repository

You seeCould not find a file named "pubspec.yaml" in <repository> <commit>

Check

Could not find a file named "pubspec.yaml" means pub cloned the repository but found no package at its root. Pub reads pubspec.yaml from the repository root unless you give a path. A repository that holds several packages keeps each one in its own folder. Look at the layout of the clone from the first step.

Check
find /tmp/pub-clone-test -name pubspec.yaml -not -path "*/.dart_tool/*"

Fix

Add a path key that is relative to the repository root and points at the folder holding the package's pubspec.yaml.

Fix
dependencies:
  my_package:
    git:
      url: https://github.com/my-org/tools.git
      path: packages/my_package

Verify

pub get resolves the package and the import in your code compiles.

Verify
flutter pub get && flutter analyze

Confirmed by dart.dev

Did this fix it?

How do I stop it coming back?

  • Pin every git dependency to a tag or a full commit hash in ref, never to a moving branch.
  • Give CI its own read-only deploy key for each private package repository, added before flutter pub get runs.
  • Run git ls-remote on the pinned ref in CI when a dependency is bumped, so a deleted tag fails early.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, Qist Bazaar, SessionBird.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.