GitHub Actions: npm install private repository

If you’re installing a private GitHub repository with npm/Yarn in GitHub Actions, then you’ll need to set up a personal access token (PAT).

For example, with the following package.json:

  "dependencies": {
    "mypackage": ""

Create a personal access token (PAT) and add it as a new repository secret to your repository’s Settings > Secrets > Actions.

In the example, the secret is named PAT.

Add the checkout and git config steps before installing the dependencies in your workflow:

# .github/workflows/my-workflow.yml
  - name: Checkout repository
    uses: actions/checkout@v3
      token: ${{ secrets.PAT }}

  - name: Configure Git
    run: git config --global --add url."https://${{ secrets.PAT }}".insteadOf ""

  - name: Install dependencies
    run: npm ci # or `yarn --frozen-lockfile`

Now you won’t get the errors during the install step:

fatal: could not read Username for '': terminal prompts disabled
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please support this site and join our Discord!