Search code examples
gitgithubgithub-actions

GitHub Action: fatal: could not read Username for 'https://github.com': Device not configured


I was trying to make git clone with Github Action on a private repo, but I am not sure how should I configure it to connect to GitHub with SSH. It is a macOS runner by the way.

At this moment, the actions/checkout is working fine but when I call git clone directly, this error is thrown.

The .yml file is provided below:

name: Release IOS
on: 
  push:
    branches:
      - github-action
jobs:
  build:
    name: Build IPA and upload to TestFlight
    runs-on: macos-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: ${{ github.head_ref }}
      - name: Check Github User
        run: |
          git --version
          git config user.name 'MyUsername'
          git config user.email 'MyEmail'
          git config user.name
          git config user.email
        env:
          NODE_AUTH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
      - name: Setup Node.js
        uses: actions/setup-node@v1
        with:
          node-version: 14.17.0
        env:
          NODE_AUTH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
      - name: Set up SSH
        uses: pioug/[email protected]
        with:
          GH_SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
      - name: Try copy a private repo
        run: git clone https://github.com/MyUsername/MyRepo.git

Solution

  • As @torek noted, the error is trying to read credentials from your terminal since it exhausted other options (config etc.)

    Since you're setting up ssh in the previous step then it seems like your intention is to use ssh so you should change the url to ssh.

    run: git clone [email protected]:MyUsername/MyRepo.git
    

    Note that there's other options as well. You could still use https but use the git extraheader cli option along with a PAT. That's actually what we do in actions/checkout for common situations.

    https://www.codegrepper.com/code-examples/shell/How+do+I+clone+a+git+repository+with+extraHeader

    From that site for completeness:

    PAT="mypat123"
    REPO_URL="https://[email protected]/myorg/myrepo/_git/myrepo/"
    AUTH=$(echo -n "x-access-token:$PAT" | openssl base64 | tr -d '\n')
    git -c http.$REPO_URL.extraheader="Authorization: Basic $AUTH" clone $REPO_URL --no-checkout --branch master
    

    Basically you have it pass your PAT as a base64 encoded header.