# CMake Error: FetchContent: Invalid git refspec for repository https://github.com/user/repo.git: 'refs/heads/mainx' is not a valid reference.

- **ID:** `cmake/fetchcontent-invalid-git-refspec`
- **Domain:** cmake
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 92%

## Root Cause

FetchContent_GitDeclare or FetchContent_Populate specifies a GIT_TAG that points to a nonexistent branch, tag, or commit hash.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| cmake 3.14 | active | — | — |
| cmake 3.20 | active | — | — |
| cmake 3.27 | active | — | — |

## Workarounds

1. **Verify the correct branch/tag name: run 'git ls-remote --heads --tags https://github.com/user/repo.git' to list all valid references, then update GIT_TAG accordingly, e.g., set(FETCHCONTENT_SOURCE_DIR_MYPROJ /local/path) or correct the tag to 'main'.** (95% success)
   ```
   Verify the correct branch/tag name: run 'git ls-remote --heads --tags https://github.com/user/repo.git' to list all valid references, then update GIT_TAG accordingly, e.g., set(FETCHCONTENT_SOURCE_DIR_MYPROJ /local/path) or correct the tag to 'main'.
   ```
2. **If using a commit hash, ensure it is the full SHA (40 characters for SHA-1) and exists on the remote: GIT_TAG "abc123def4567890abcdef1234567890abcdef12".** (90% success)
   ```
   If using a commit hash, ensure it is the full SHA (40 characters for SHA-1) and exists on the remote: GIT_TAG "abc123def4567890abcdef1234567890abcdef12".
   ```

## Dead Ends

- **Cleaning the build directory and re-running cmake without changing GIT_TAG** — The refspec is still invalid; cleaning only removes cached content, but the same tag will fail again. (100% fail)
- **Setting FETCHCONTENT_UPDATES_DISCONNECTED to ON to skip fetching** — This prevents fetching entirely, so the dependency won't be populated at all, causing a different error. (95% fail)
