• 22-Jan-2023
Lightrun Team
Author Lightrun Team
Share
This article is about fixing Error fatal could not read Username for 'httpsgithub.com' terminal prompts disabled in Actions Checkout

Error: fatal: could not read Username for ‘https://github.com’: terminal prompts disabled in Actions Checkout

Lightrun Team
Lightrun Team
22-Jan-2023

Explanation of the problem

The problem described is an error when attempting to use the “actions/checkout@v2” action to perform a rollback flow on Github Workflows. The error message received is “fatal: could not read Username for ‘https://github.com‘: terminal prompts disabled”.

The workflow in question is a job named “Dev Deploy” that runs when a workflow is completed, specifically when the “Versioning” workflow runs. The job has two steps, “Fail” and “rollback-on-failure”. The “Fail” step exits with a status code of 1, and the “rollback-on-failure” step runs if the previous step exits with a status code of failure. In this step, the action “actions/checkout@v2” is used to checkout the repository in order to rollback the commits.

The issue is that the action “actions/checkout@v2” requires a Personal Access Token (PAT) to be passed as a parameter to access the repository, and this PAT is being passed as a secret named “WORKFLOW_TOKEN”. However, this action does not allow to set the username before trying to fetch the repository, so the error message “fatal: could not read Username for ‘https://github.com‘: terminal prompts disabled” is generated.

      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
          token: ${{ secrets.WORKFLOW_TOKEN }}

Troubleshooting with the Lightrun Developer Observability Platform

Getting a sense of what’s actually happening inside a live application is a frustrating experience, one that relies mostly on querying and observing whatever logs were written during development.
Lightrun is a Developer Observability Platform, allowing developers to add telemetry to live applications in real-time, on-demand, and right from the IDE.

  • Instantly add logs to, set metrics in, and take snapshots of live applications
  • Insights delivered straight to your IDE or CLI
  • Works where you do: dev, QA, staging, CI/CD, and production

Start for free today

Problem solution for Error: fatal: could not read Username for ‘https://github.com’: terminal prompts disabled in Actions Checkout

The error message “fatal: could not read Username for ‘https://github.com‘: terminal prompts disabled” is typically encountered when using the GitHub Actions “actions/checkout@v2” action to check out a repository in a workflow. This error occurs because the action is unable to determine the username associated with the repository, which is required for authentication.

This error can occur for several reasons, such as:

  • The Personal Access Token (PAT) passed as a parameter to the action does not have the necessary permissions to access the repository.
  • The PAT passed as a parameter is invalid or has been revoked.
  • The PAT passed as a parameter is not associated with a GitHub account, and therefore does not have a username.

To resolve this issue, you can use the GitHub Actions “actions/checkout@v3” action, which allows to use both, a token and a username, as input.

      - name: Checkout
        uses: actions/checkout@v3
        with:
          repository: ${{github.repository}}
          token: ${{secrets.PAT}}
          username: ${{secrets.USERNAME}}

Another solution could be to check that the PAT passed as a parameter to the action has the necessary permissions to access the repository, and that it is still valid. Additionally, check that the PAT is associated with a GitHub account and that the account has the necessary permissions to access the repository.

It’s also important to make sure that the repository url is correct and that you’re authenticated properly.

Other popular problems with Checkout

Problem: Personal Access Token (PAT) issues

One common problem with using the “actions/checkout@v2” action is that it requires a PAT to be passed as a parameter to access the repository. However, if the PAT passed as a parameter does not have the necessary permissions to access the repository, or if it is invalid or has been revoked, the action will fail with an error message similar to “fatal: could not read Username for ‘https://github.com‘: terminal prompts disabled”.

      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
          token: ${{ secrets.PAT }}

Solution:

To resolve this issue, you can check that the PAT passed as a parameter to the action has the necessary permissions to access the repository, and that it is still valid. Additionally, check that the PAT is associated with a GitHub account and that the account has the necessary permissions to access the repository.

Problem: Branch not found error

Another common problem with using the “actions/checkout@v2” action is that it may fail with an error message similar to “fatal: repository ‘https://github.com/OWNER/REPO.git/‘ not found” when trying to check out a specific branch.

      - name: Checkout
        uses: actions/checkout@v2
        with:
          repository: ${{github.repository}}
          ref: ${{ env.BRANCH_NAME }}

This issue can occur when the branch specified in the “ref” parameter of the action does not exist in the repository.

Solution:

To resolve this issue, you can check that the branch specified in the “ref” parameter exists in the repository, and that the repository URL is correct.

Problem: Incorrect repository URL

Another common problem with using the “actions/checkout@v2” action is that it may fail with an error message similar to “fatal: repository ‘https://github.com/OWNER/REPO.git/‘ not found” when the repository URL specified is incorrect.

      - name: Checkout
        uses: actions/checkout@v2
        with:
          repository: https://github.com/OWNER/REPO.git

Solution:

To resolve this issue, you can check that the repository URL specified in the action is correct. You can also use the parameter ${{github.repository}} that automatically gets the repository URL where the action is running.

It is important to keep in mind that “actions/checkout@v3” allows to use both, a token and a username, as input, which might help in some of the above issues.

A brief introduction to Checkout

Actions Checkout is a GitHub Action that allows developers to check out a specific repository, branch, or tag in their GitHub Actions workflow. This action is built on top of the Git command-line tool, and provides a simple and convenient way for developers to check out code within their workflow without having to manually run Git commands.

The Actions Checkout action can be used in a variety of use cases, such as continuous integration and continuous deployment workflows. By using this action, developers can easily check out the desired code, run tests, and deploy the code to a specific environment. Additionally, the action supports various parameters such as repository, ref, and token, which can be used to specify the repository URL, branch or tag, and Personal Access Token (PAT) for the repository, respectively.

Most popular use cases for Checkout

  1. Checking out a specific branch or tag in a repository: Actions Checkout can be used to check out a specific branch or tag in a repository within a GitHub Actions workflow. This can be useful for continuous integration and continuous deployment workflows, where the code needs to be checked out from a specific branch or tag before it is deployed to a specific environment.
      - name: Checkout
        uses: actions/checkout@v2
        with:
          repository: ${{github.repository}}
          ref: ${{ env.BRANCH_NAME }}
  1. Checking out a specific repository: Actions Checkout can also be used to check out a specific repository within a GitHub Actions workflow. This can be useful for workflows that need to check out code from a different repository than the one the action is running on.
      - name: Checkout
        uses: actions/checkout@v2
        with:
          repository: https://github.com/OWNER/REPO.git
  1. Automating Git operations in a workflow: Actions Checkout provides a simple and convenient way for developers to automate Git operations within their workflow without having to manually run Git commands. This can help to streamline the development process and improve the efficiency of the workflow.
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
          token: ${{ secrets.PAT }}

This can be particularly useful for workflows that involve multiple Git operations, such as fetching, pulling, or pushing code. With Actions Checkout, developers can automate these operations, reducing the need for manual intervention and minimizing the risk of errors.

Share

It’s Really not that Complicated.

You can actually understand what’s going on inside your live applications. It’s a registration form away.

Get Lightrun

Lets Talk!

Looking for more information about Lightrun and debugging?
We’d love to hear from you!
Drop us a line and we’ll get back to you shortly.

By submitting this form, I agree to Lightrun’s Privacy Policy and Terms of Use.