"fatal: --local can only be used inside a git repository"

Must-share information :

  • Version:
  • to implement sonarqube inside a repository that has another repository inside it
  • implemented the sonarqube for the parent repository but getting error when trying to push inside the child repository


Welcome to the community!

Please provide the full job log, starting from checkout through the end of analysis.


HI @ganncamp
Thank you for responding :slight_smile:

I am trying to build an workflow that has an subdirectory inside the main repository.
Meaning i have two repositories.
For example:
Repo1 and Repo2.
Repo 1 has the project and it has the main workflow actions, and when ever it makes commits and merges them into the project, the sha of the merge will be output inside the repo2, in a specific file, let’s say info-file.txt.

Now, without adding the sonar jobs, it works fine.
When i add the sonar jobs, whenever it tries to checkout the repo2 it gives me an error like this :
/usr/bin/git config --local --name-only --get-regexp core.sshCommand

28 Error: fatal: --local can only be used inside a git repository

29 /usr/bin/git submodule foreach --recursive git config --local --name-only --get-regexp ‘core.sshCommand’ && git config --local --unset-all ‘core.sshCommand’ || :

30 Error: fatal: not a git repository (or any of the parent directories): .git

31 Error: The process ‘/usr/bin/git’ failed with exit code 128.

I don’t seem to find the solution for this problem.

P.s. I have tried to remove the first repo, or change the .git folder, but they were no help.

Best Regards,

Hi Vs,

You’re saying that adding analysis to your pipeline breaks checkout?

Now I’d like to see the pipeline and the entire job log, please.


Hi @ganncamp

I have made an example of the workflow:

name: repo1
      - dev
    runs-on: ubuntu-latest
      - name: Checkout repo code inside GitHub Actions container
        uses: actions/checkout@v2
          fetch-depth: 0
      - name: Quality check with Sonar Qube
        uses: sonarsource/sonarqube-scan-action@master
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
          SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
      - name: Get short git sha 
        id: sha_short_var
        run: echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
      - name: Checkout second repo
        uses: actions/checkout@v2
          repository: name/repo2
          persist-credentials: false
          fetch-depth: 0
          ref: devs
          token: ${{ secrets.GH_TOKEN }}
      - name: Update manifests
          ID: ${{ env.SHORT_SHA }}
        run: |
          sleep 1
          sed -i -e "s/The latest commit ID:.*/The latest commit ID: $SHORT_SHA <\/h1>/g" repo1/merge-file.html
          git config --global user.email "${{ secrets.GH_EMAIL }}"
          git config --global user.name "${{ secrets.GH_USER }}"
          git add .
          git commit -m "The latest commit is with this ID: ${{ env.SHORT_SHA }}"
      - name: Push manifests file changes
        uses: ad-m/github-push-action@master
          github_token: ${{ secrets.GH_TOKEN }}
          repository: name/repo2

Hope this help :slight_smile:

Looking forward to hearing from you
Best Regards

Hi VS,

Can we see the log from your CI, please?


Hi @ganncamp

Here are the logs from the failed job :slight_smile:

Hope this helps

1_ci (1).txt (39.4 KB)
1_ci.txt (450 Bytes)


This log doesn’t seem to relate to your initial complaint:


Hi @ganncamp

Sorry, I did not send all the logs.
The first 5 logs:
1_Set up job.txt (2.2 KB)
2_Build sonarsourcesonarqube-scan-action@master.txt (3.3 KB)
3_Checkout repo code inside GitHub Actions container.txt (19.6 KB)
4_Quality check with Sonar Qube.txt (9.3 KB)
5_Get short git sha.txt (309 Bytes)

6_Remove existing repo.txt (297 Bytes)
7_Checkout second repo.txt (2.3 KB)
16_Post Checkout second repo.txt (48 Bytes)
17_Post Quality check with Sonar Qube.txt (1.5 KB)
18_Post Checkout repo code inside GitHub Actions container.txt (48 Bytes)

And the last one.
19_Complete job.txt (59 Bytes)

I hope it helps.

I am only asking this, because it looks like that sonnar jobs are giving errors.
I have tried to put them as the last one, and it again fails. But without them it works perfect.

I can send you logs of the working workflow, if you like it.

Best Regards,

Hi VS,

So in one pipeline/workspace you:

  • check out & analyze project 1 - successfully
  • clean out the workspace
  • check out project 2 - and here there’s an error when analysis is included in the pipeline

I don’t understand why you would structure it like this instead of having a job/pipeline per project.

And here’s what I see in the step 7 log:

2022-12-13T15:39:44.6669975Z Syncing repository: ***/repo2
2022-12-13T15:39:44.6678343Z Working directory is '/home/runner/work/repo1/repo1'

So you’ve synched repo2 into the repo1 working directory…

2022-12-13T15:39:44.6850796Z Adding repository directory to the temporary git global config as a safe directory
2022-12-13T15:39:44.6856603Z [command]/usr/bin/git config --global --add safe.directory /home/runner/work/repo1/repo1
2022-12-13T15:39:44.6907822Z [command]/usr/bin/git config --local --get remote.origin.url
2022-12-13T15:39:44.6939725Z https://github.com/***/repo1
2022-12-13T15:39:44.6947533Z Deleting the contents of '/home/runner/work/repo1/repo1'

And then you delete all the contents of the directory, including presumably the .git directory, which marks it as a git repository

2022-12-13T15:39:44.7110349Z [command]/usr/bin/git config --local --name-only --get-regexp core.sshCommand
2022-12-13T15:39:44.7167766Z ##[error]fatal: --local can only be used inside a git repository

And then you experience an error because it’s not a git repository.

This seems unrelated to analysis to me…


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.