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 showFix it fast
Most common cause, 1 of 4Git 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.
git --version
flutter pub getShort 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.
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.
git clone https://github.com/my-org/my_package.git /tmp/pub-clone-testThen find the line you see in this list and open its fix:
- 1Git is not installed, or pub cannot see it on PATH
Cannot find a Git executable. Please ensure Git is correctly installed. - 2The repository is private and this machine has no access
The Git error's stderr shows a login prompt, an authentication failure or a publickey rejection; the clone works on another machine - 3The ref in pubspec.yaml does not exist in the repository
Could not find git ref '<name>' - 4The package sits in a subfolder of the repository
Could 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.gitCannot 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.
git --version
which git # macOS / Linux
where git # WindowsFix
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.
git --version
flutter pub getVerify
flutter pub get gets past the git dependency and writes it to pubspec.lock.
grep -n -A4 "my_package:" pubspec.lockConfirmed by github.com
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.
ssh -T git@github.comFix
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.
dependencies:
my_package:
git:
url: git@github.com:my-org/my_package.gitVerify
ssh -T git@github.com greets you by user name, and pub get then clones the repository.
flutter pub getConfirmed by dart.dev
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.
git ls-remote https://github.com/my-org/my_package.git
git ls-remote --tags https://github.com/my-org/my_package.gitFix
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.
dependencies:
my_package:
git:
url: https://github.com/my-org/my_package.git
ref: v2.1.0Verify
Run pub get again; pubspec.lock now records the commit that the ref points to.
flutter pub get && grep -n -A6 "my_package:" pubspec.lockConfirmed by dart.dev
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.
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.
dependencies:
my_package:
git:
url: https://github.com/my-org/tools.git
path: packages/my_packageVerify
pub get resolves the package and the import in your code compiles.
flutter pub get && flutter analyzeConfirmed by dart.dev
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.