githubflutterpackageyamlpassword-protection

How can I add a private package from GitHub with my user and password to my pubspec.yaml?


My question is simple. I can clone a private git repository using

git clone https://my_user_name:my_password@github.com/my_account/my_package.git

now, How can I add a private package from GitHub with my user and password to my pubspec.yaml?

dependencies:
  my_package:
    git: https://my_user_name:my_password@github.com/my_account/my_package.git 

In my case, I am working with Flutter/Dart in IntelliJ IDEA. But assume the solution should work on any environment and other programming languages.


Solution

  • Finally, after test and test and test... found two good things:

    First: We can use

    dependencies:
      my_package:
        git: 
          url: https://my_user_name:my_password@github.com/my_account/my_package.git 
          ref: stable
          # ref: master or any other branch in your private package.
    

    and with ref: we can select any branch by name.

    EDIT by Nov. 5, 2023

    Rather than "my_password" you must provide a valid token generated in your GitHub account. See comments below.