# hudson.plugins.git.GitException: Could not checkout branch 'main' with start point 'origin/main'

- **ID:** `cicd/jenkins-pipeline-checkout-failed-git`
- **Domain:** cicd
- **Category:** build_error
- **Error Code:** `GIT_CHECKOUT_FAILED`
- **Verification:** ai_generated
- **Fix Rate:** 84%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Jenkins 2.440 | active | — | — |
| Git Plugin 5.2.0 | active | — | — |
| Git 2.40 | active | — | — |

## Workarounds

1. **Clean workspace and retry: add `cleanWs()` in pipeline or `git clean -fdx` before checkout, and ensure branch exists: `git branch -r | grep origin/main`** (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`
   ```
2. **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]])`** (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]])`
   ```
3. **Force fetch remote refs before checkout: `git fetch origin +refs/heads/main:refs/remotes/origin/main --force` in pipeline script** (88% success)
   ```
   Force fetch remote refs before checkout: `git fetch origin +refs/heads/main:refs/remotes/origin/main --force` in pipeline script
   ```

## Dead Ends

- **** — Workspace deletion alone doesn't fix remote connectivity issues or stale git refs; lock files may reoccur. (50% fail)
- **** — Plugin reinstall doesn't affect remote repo state or local git configuration; overkill for checkout issue. (70% fail)
- **** — Timeout increase doesn't resolve missing branches or authentication failures; only delays failure. (60% fail)
