I am trying to run git commands on windows self hosted runner which is configured on Amazon EC2 instance. I have installed the git bash on the same machine where my runner is configured and set it's path in the Environment Variables.

Now when I am running this piece of code:

  needs: test # This test job is deployed on GitHub Hosted Runner
  runs-on: [ self-hosted, Windows, X64 ]
      shell: cmd

    - name: Checkout code repository
      uses: actions/checkout@v2
    - name: Git Commit SHA command
      shell: powershell
      run: |
        $output = C:\"Program Files"\Git\cmd\git rev-parse --short=4 HEAD
        echo $output

I am getting this error: Run C:"Program Files"\Git\cmd\git rev-parse HEAD fatal: not a git repository (or any of the parent directories): .git Error: Process completed with exit code 1.

I got the solution for this that I need to clone the repository inside the EC2 instance where the runner is configured and post that I need to run git init command to initialize it as a git repo but I have a reason not to clone it as being a client I don't want the third party will able to access my code.

Is there any alternative which helps me to get rid of this error?