如何使用我的用户名和密码将 GitHub 上的私有包添加到我的 pubspec.yaml 中?

abn*_*h69 7 yaml github package password-protection flutter

我的问题很简单。我可以使用克隆私有 git 存储库

git clone https://my_user_name:my_password@github.com/my_account/my_package.git
Run Code Online (Sandbox Code Playgroud)

现在,如何使用我的用户名和密码将 GitHub 上的私有包添加到我的 pubspec.yaml 中?

dependencies:
  my_package:
    git: https://my_user_name:my_password@github.com/my_account/my_package.git 
Run Code Online (Sandbox Code Playgroud)

就我而言,我正在 IntelliJ IDEA 中使用 Flutter/Dart。但假设该解决方案应该适用于任何环境和其他编程语言。

abn*_*h69 8

最后,经过反复测试……发现了两个好东西:

第一:我们可以使用

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.
Run Code Online (Sandbox Code Playgroud)

并使用ref:我们可以按名称选择任何分支。

2023 年 11 月 5 日之前编辑

您必须提供在 GitHub 帐户中生成的有效令牌,而不是“my_password”。请参阅下面的评论。