Search code examples
flutterdartdart-pub

How to specify a branch of a local git repository in my pubspec.yaml configuration?


Given I have a Dart/Flutter project that is using local a package (which is a git repository), how can I specify a branch for that local package? For example I have the following development directory:

.
├── my_application
└── my_package

In my my_package I have a branch called new-functionality. I want to use the new-functionality branch without doing a git-checkout in the repository.

In my_application/pubspec.yaml, I would like to specify that local package and branch along the lines of this:

my_package:
  git:
    url: ../my_package # I know this is not valid
    ref: new-functionality

In the Dart/Flutter Package Dependency documentation I couldn't find any way to achieve this with a git repository on my local machine.

Can I specify a branch for that local git repository package in my project's pubspec.yaml?


Solution

  • You can use a file:// URL to refer to a local Git repository. For example:

    dependencies:
      my_package:
        git:
          url: file:///home/Apealed/git/my_package
          ref: new-functionality