Chris G.
Chris G.

Reputation: 25974

How do you force 'pub get' to get latest from git?

I have a git dependency in my pubspec.yaml file, how can I force it to be updated when new changes occur in the git repo?

flutter pub get / pub get

It does not get the latest, as it is in .pub-cache/git/

Is there a way to force a specific dependency to update from a git repo referenced in pubspec.yaml?

Upvotes: 39

Views: 24435

Answers (5)

Rafhaela
Rafhaela

Reputation: 93

What specifically worked for me was:

Let in pubspec.yaml

your_package:
git:
  url: [email protected]/your-package.git
  ref: master

Deleting pubcpec.lock and running flutter pub get didn't really work for me. So to upgrade it, just run

flutter pub upgrade your_package

It's also possible forcing it locally by going into pubspec.lock, search the package and change the resolved-ref to the last hash commit from the branch. Just make sure this resolved-ref is updated in pubspec.lock.

Upvotes: 1

Xavier
Xavier

Reputation: 4005

In your pubspec.yaml, you can specify a particular git commit:

dependencies:
  http2:
    git:
      url: 'https://github.com/dart-lang/http2.git'
      ref: 'c31df28c3cf076c9aacaed1d77f45b66bb2e01a6'

Or if you specify only a branch in "ref":

dependencies:
  http2:
    git:
      url: 'https://github.com/dart-lang/http2.git'
      ref: 'master'

You need to force the update with flutter pub upgrade

Upvotes: 61

Han Parlak
Han Parlak

Reputation: 777

flutter packages upgrade upgrades all packages' sub-version which might not be the thing you are looking for (using some specific package version for some reason etc.). pub cache repair gets the job done by reinstalling all the packages but it also takes time. Working with refs has disadvantages like missing the most current updates on a branch.

There are 2 other options/hacks to avoid all this:

  1. delete package info from pubspec.lock and run flutter pub get
  2. update ref value to most current commit's hash value. run flutter pub get then rewrite your branch name again to your ref value.

Upvotes: 1

atreeon
atreeon

Reputation: 24107

  1. Run flutter clean and then pub get (if using flutter then add flutter before pub)

  2. Ensure to update your package's version number; if the version is the same as the last commit, the package won't get updated.

  3. run pub upgrade

  4. if it still doesn't work you can run pub cache repair which reinstalls all your packages

EDIT

  1. ensure dependency is not in dev_dependencies section (yup, that was today!)

Upvotes: 12

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657496

Use

flutter packages upgrade

to get latest.

flutter packages get

only gets latests the first time and writes the resolved versions into pubspec.lock Subsequent flutter packages get runs then try to get the versions listed in pubspec.lock,
while flutter packages upgrade always ignores pubspec.lock

Upvotes: 44

Related Questions