GIT_CHECKOUT_FAILED
cicd
build_error
ai_generated
true
hudson.plugins.git.GitException: Could not checkout branch 'main' with start point 'origin/main'
ID: cicd/jenkins-pipeline-checkout-failed-git
84%Fix Rate
86%Confidence
1Evidence
2024-04-18First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| Jenkins 2.440 | active | — | — | — |
| Git Plugin 5.2.0 | active | — | — | — |
| Git 2.40 | active | — | — | — |
Root Cause
Jenkins Git plugin fails to checkout because the branch or commit reference is missing, the remote repository is unreachable, or the workspace has stale lock files from a previous aborted build.
generic中文
Jenkins Git插件无法检出,因为分支或提交引用丢失、远程仓库不可达,或工作空间存在之前中止构建的陈旧锁文件。
Official Documentation
https://plugins.jenkins.io/git/Workarounds
-
85% success Clean workspace and retry: add `cleanWs()` in pipeline or `git clean -fdx` before checkout, and ensure branch exists: `git branch -r | grep origin/main`
Clean workspace and retry: add `cleanWs()` in pipeline or `git clean -fdx` before checkout, and ensure branch exists: `git branch -r | grep origin/main`
-
90% success Use shallow clone with depth 1 to avoid stale refs: `checkout([$class: 'GitSCM', branches: [[name: '*/main']], extensions: [[$class: 'CloneOption', depth: 1, noTags: true, shallow: true]])`
Use shallow clone with depth 1 to avoid stale refs: `checkout([$class: 'GitSCM', branches: [[name: '*/main']], extensions: [[$class: 'CloneOption', depth: 1, noTags: true, shallow: true]])`
-
88% success Force fetch remote refs before checkout: `git fetch origin +refs/heads/main:refs/remotes/origin/main --force` in pipeline script
Force fetch remote refs before checkout: `git fetch origin +refs/heads/main:refs/remotes/origin/main --force` in pipeline script
中文步骤
Clean workspace and retry: add `cleanWs()` in pipeline or `git clean -fdx` before checkout, and ensure branch exists: `git branch -r | grep origin/main`
Use shallow clone with depth 1 to avoid stale refs: `checkout([$class: 'GitSCM', branches: [[name: '*/main']], extensions: [[$class: 'CloneOption', depth: 1, noTags: true, shallow: true]])`
Force fetch remote refs before checkout: `git fetch origin +refs/heads/main:refs/remotes/origin/main --force` in pipeline script
Dead Ends
Common approaches that don't work:
-
50% fail
Workspace deletion alone doesn't fix remote connectivity issues or stale git refs; lock files may reoccur.
-
70% fail
Plugin reinstall doesn't affect remote repo state or local git configuration; overkill for checkout issue.
-
60% fail
Timeout increase doesn't resolve missing branches or authentication failures; only delays failure.