Checkout: no .git folder

Created on 21 Aug 2020  路  18Comments  路  Source: actions/checkout

minikube Make uses git log for getting the commit sha for minikube version,

git log doesn't work in checkouted source code

when I run git log --pretty=oneline
I get this error:

 Not a git repository (or any of the parent directories): .git

Most helpful comment

I was using self-hosted runner. And it had no .git folder showed me logs as below:

Getting Git version info
  Working directory is '/root/actions-runner/_work/<project>/<project>'
  /usr/bin/git version
  git version 2.17.1
The repository will be downloaded using the GitHub REST API
To create a local Git repository instead, add Git 2.18 or higher to the PATH
Downloading the archive
Writing archive to disk
Extracting the archive

This means, the repository got downloaded using the GitHub REST API, which meant to dowloaded differently.

So for debugging what's going around, I tried on the ubuntu-latest instead of self-hosted and it showed me log something like this:

Getting Git version info
  Working directory is '/home/runner/work/<project>/<project>'
  /usr/bin/git version
  git version 2.28.0
Initializing the repository
  /usr/bin/git init /home/runner/work/<project>/<project>
  Initialized empty Git repository in /home/runner/work/<project>/<project>/.git/
  /usr/bin/git remote add origin https://github.com/<org>/<project>
Disabling automatic garbage collection
  /usr/bin/git config --local gc.auto 0

After comparing those two logs: one is using Git version: 2.17.1, and another one is using Git version: 2.28.0.

Hence, after updating the Git version (>= 2.18) into latest one, the issue got resolved in my case.

All 18 comments

If you are running on a self-hosted runner, is your CI checking out your project using git or github REST API ?

I was using self-hosted runner. And it had no .git folder showed me logs as below:

Getting Git version info
  Working directory is '/root/actions-runner/_work/<project>/<project>'
  /usr/bin/git version
  git version 2.17.1
The repository will be downloaded using the GitHub REST API
To create a local Git repository instead, add Git 2.18 or higher to the PATH
Downloading the archive
Writing archive to disk
Extracting the archive

This means, the repository got downloaded using the GitHub REST API, which meant to dowloaded differently.

So for debugging what's going around, I tried on the ubuntu-latest instead of self-hosted and it showed me log something like this:

Getting Git version info
  Working directory is '/home/runner/work/<project>/<project>'
  /usr/bin/git version
  git version 2.28.0
Initializing the repository
  /usr/bin/git init /home/runner/work/<project>/<project>
  Initialized empty Git repository in /home/runner/work/<project>/<project>/.git/
  /usr/bin/git remote add origin https://github.com/<org>/<project>
Disabling automatic garbage collection
  /usr/bin/git config --local gc.auto 0

After comparing those two logs: one is using Git version: 2.17.1, and another one is using Git version: 2.28.0.

Hence, after updating the Git version (>= 2.18) into latest one, the issue got resolved in my case.

I'm using GitHub itself and not a self hosted runner but keep running into the same issue. We use the .git folder during our scripts.

same issue :(

As @RaiBnod already mentioned, upgrading git did the trick for me, too (in my case 2.11.0 -> 2.21.0).

Also seeing lack of .git folder, git reports git version 2.20.1 (believe we are in ubuntu-latest), are there any other known causes?

Why is this version-specific, hasn't git clone created a .git folder standardly for a very long time?

EDIT: Hmm, another version of git is active somehow somewhere? Thanks for the clues about what to investigate...

The repository will be downloaded using the GitHub REST API
To create a local Git repository instead, add Git 2.18 or higher to the PATH

Is this referring to the copy of git installed inside of actions/checkout@v2? How can I upgrade that?

Tried apt-get install git as a step before checkout. Please kill me.

Package git is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'git' has no installation candidate

Is the root cause a TLS thing?

EDIT AGAIN: Apparently what I needed to do was delete this from the workflow file, because then it ... uses something newer? I have no idea:

       container:
           image: ubuntu:latest

I assume that's a restatement of what's already been said above. Included for anyone else who's as clueless as I am.

Self hosted: upgrading git for debian-based distros:

sudo apt-get install -y software-properties-common \
    && sudo apt-get update \
    && sudo add-apt-repository -y ppa:git-core/ppa \
    && sudo apt-get update \
    && sudo apt-get install -y git

Either run it before the checkout action, or, if the runner is a docker container, add as a RUN command

This was also an issue for me (due to use of setuptools_scm on a project I am running in a container) and it took me a good while to find this issue. I think this difference in behavior should be more prevalent in the README.

I was using self-hosted runner. And it had no .git folder showed me logs as below:

Getting Git version info
  Working directory is '/root/actions-runner/_work/<project>/<project>'
  /usr/bin/git version
  git version 2.17.1
The repository will be downloaded using the GitHub REST API
To create a local Git repository instead, add Git 2.18 or higher to the PATH
Downloading the archive
Writing archive to disk
Extracting the archive

This means, the repository got downloaded using the GitHub REST API, which meant to dowloaded differently.

So for debugging what's going around, I tried on the ubuntu-latest instead of self-hosted and it showed me log something like this:

Getting Git version info
  Working directory is '/home/runner/work/<project>/<project>'
  /usr/bin/git version
  git version 2.28.0
Initializing the repository
  /usr/bin/git init /home/runner/work/<project>/<project>
  Initialized empty Git repository in /home/runner/work/<project>/<project>/.git/
  /usr/bin/git remote add origin https://github.com/<org>/<project>
Disabling automatic garbage collection
  /usr/bin/git config --local gc.auto 0

After comparing those two logs: one is using Git version: 2.17.1, and another one is using Git version: 2.28.0.

Hence, after updating the Git version (>= 2.18) into latest one, the issue got resolved in my case.

Any ideas on getting the self-hosted up to a later version? I have the same issue but the older version of git is limiting other features we want. I need at least 2.18 or higher.

2021-04-01: I still see the same problem when running on GitHub itself.

Self hosted: upgrading git for debian-based distros:

sudo apt-get install -y software-properties-common \
    && sudo apt-get update \
    && sudo add-apt-repository -y ppa:git-core/ppa \
    && sudo apt-get update \
    && sudo apt-get install -y git

Either run it before the checkout action, or, if the runner is a docker container, add as a RUN command

Even after running those ^ on a self-hosted docker image I still get the same errors. For some reason I only get a 2.7 version of GIT installed and nothing newer. Cannot seem to get past it.

UPDATE:

Got it working - rather than running git install on Dockerfile, just run it before the checkout phase like suggested above. Here's how mine looks:

steps:
      - name: Force Install GIT latest
        run: |
          apt-get install -y software-properties-common \
          && apt-get update \
          && add-apt-repository -y ppa:git-core/ppa \
          && apt-get update \
          && apt-get install -y git

      # Checkout the repository to the GitHub Actions runner
      - name: Checkout
        uses: actions/checkout@v2

Works on Ubuntu:18.04. Cheers 馃憤馃徏

I still see the failure when using git 2.20.1 Besides, updating is just a workaround: the bug should be fixed in order to support older git versions.

@amagana3 The problem is you are modifying the "base os" of the runner with that.

Here is my solution to this bug, until it is fixed upstream -- "pipe" the action@v2 to run inside a docker context of ubuntu:20.04 and setup git (or use a container you have with git that will run checkout):

on:
  push:
    branches:
      - master
  pull_request:
jobs:
  some-job:
    name: some-job-name
    runs-on: ubuntu-latest
    container: ubuntu:20.04
    steps:
      - name: Obtain Latest Git ONLY within container for checkout
        run: |
          apt-get update
          apt-get install -y git

      - name: Checkout Repo Action
        uses: actions/checkout@v2

Key parts:

 runs-on: ubuntu-latest --> this is a self-hosted label. (in my case, Ubuntu 18.04)

vs

    container: ubuntu:20.04 --> this is the container used for the "actions/checkout@v2"

This is actually a pretty elegant solution to this problem imo.

Here is a much smaller and quicker version via alpine:

on:
  push:
    branches:
      - master
  pull_request:
jobs:
  some-job:
    name: some-job-name
    runs-on: ubuntu-latest
    container: alpine:latest
    steps:
      - name: Obtain Latest Git ONLY within container for checkout
        run: apk add git --update-cache

      - name: Checkout Repo Action
        uses: actions/checkout@v2

Again, noting that alpine:latest is just used to run the actions/checkout@v2 and will provide the needed version of git.

@ventz Thanks for this! However, using shell: bash fails when I add the container: alpine:latest line, I assume we now have to deal with this manually though.

Explicit error:

OCI runtime exec failed: exec failed: container_linux.go:367: starting container process caused: exec: "bash": executable file not found in $PATH: unknown

@mrowles Alpine doesn't have bash by default - it uses ash (the almquist shell)

If you need bash, you can just add it as a package to the pre-checkout line.
run: apk add git bash --update-cache

With that said, I suspect you may have something else going on within your action config, because in this case the 'container: alpine:latest' is only used for the checkout action, and the "run" before it is to populate the alpine container. (ex: if we were using another image that had git, or for example ubuntu -- we would not need that step). So, I am assuming you are adding additional steps which are not wrapping other actions, and thus not executed with the container? (ex: directly with the run command?).

@ventz Got it! So I'll need to install bash, aws etc. if I was to use anything not provided. No dramas, thanks for the help!

For future people, my main problem is not so much the .git folder missing, but actually the .yarn folder, so I'm seeing if updating git fixes this also.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aaronsteers picture aaronsteers  路  3Comments

lukka picture lukka  路  6Comments

gitfool picture gitfool  路  3Comments

chorrell picture chorrell  路  4Comments

bk2204 picture bk2204  路  3Comments