checkout
checkout copied to clipboard
no .git folder
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
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 ofself-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 aRUN
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.
@mrowles Yes. My suggestion is to keep it all wrapped into nice clean containers that you own, and then just call them either directly, or with custom actions. It makes the actions yaml config very clean, fast, and efficient. (Especially if you are not installing things you won't need at each run. Again, the git example above is not this on purpose to demonstrate use case)
I would like to add my personal findings. Adding the following to the GH Actions workflow file, actions/checkout@v2 will not create the .git
folder, or atleast all other actions I use complain about the current directory not being a git repository. And the OpenJDK should not be interfering with any git operations or actions.
container:
image: openjdk:16-jdk
Simply removing the snippet, the workflow works fine again. I have run a simple test workflow just earlier and I've noticed that with the OpenJDK image, git
does not seem to exist on PATH
, and actions/checkout@v2
therefore does not git clone
and instead uses the GitHub REST API to download the repository. You can also see how the working directory is somewhere completely different in the two runs. See https://github.com/spnda/ghactionstest/actions/runs/907433837.
So this seems to rather be an issue with actions or docker not setting up the environment properly and not with this action, no?
I kept getting the error
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
I re-installed the https://github.com/actions/runner package after installing the correct git version on the machine and it worked.
This is what I ended up with, pretty sure it's not the most efficient solution since it has to be run at every job (since each job is a new instance), but it works well:
someNodeAppDeploymentJob:
needs: [somePreReq, someOtherPreReq]
runs-on: ubuntu-latest
steps:
- name: Setup OS
run: |
sudo apt-get update
sudo apt-get upgrade
- name: Setup Git
run: |
sudo apt-get install git
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '12' # 14 had issues for me here at the time of build
- name: Checkout repository
uses: actions/checkout@v2
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
You can force Checkout to get the .git
folder by setting the keyword fetch-depth
to some value. A fetch-depth
of zero forces it to get the entire history. The default value of ''
gets no history, and hence no folder.
Example:
- name: Checkout repo
uses: actions/checkout@v2
with:
repository: my-project/my-repo
path: my-repo
fetch-depth: 0
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 aRUN
command
Had to upgrade git before checking out the repo
steps:
- name: upgrade git
run: |
apk add --update
apk add git
git --version
- name: Checkout repository
uses: actions/checkout@v2
This causes an issue here: https://github.com/actions/runner/issues/763
For those looking to solve this issue this worked for me:
https://github.com/actions/checkout/issues/701#issuecomment-1139627817
There is also fetch-tags: true
option for actions/checkout
but that didn't seem to work
https://github.com/actions/checkout/pull/579