|
| 1 | +id: runner-environment-432 |
| 2 | +title: "actions/checkout Fails on Windows When Repository Contains Branch Name Prefixes Differing Only by Case" |
| 3 | +category: runner-environment |
| 4 | +severity: error |
| 5 | +tags: |
| 6 | + - checkout |
| 7 | + - windows |
| 8 | + - case-insensitive |
| 9 | + - git-refs |
| 10 | + - branch-naming |
| 11 | + - filesystem |
| 12 | + - ntfs |
| 13 | + - case-collision |
| 14 | +patterns: |
| 15 | + - regex: 'cannot lock ref.*exists.*cannot create' |
| 16 | + flags: 'i' |
| 17 | + - regex: 'fatal: cannot create.+directory.+[Ff]ile exists' |
| 18 | + flags: 'i' |
| 19 | + - regex: 'error: refs/remotes/origin/.+: cannot lock ref' |
| 20 | + flags: 'i' |
| 21 | +error_messages: |
| 22 | + - "error: cannot lock ref 'refs/remotes/origin/Feature/tarun': 'refs/remotes/origin/feature' exists; cannot create 'refs/remotes/origin/Feature'" |
| 23 | + - "fatal: cannot create directory at 'Feature': File exists." |
| 24 | + - "error: Your local changes to the following files would be overwritten by checkout" |
| 25 | +root_cause: | |
| 26 | + On Windows runners, `actions/checkout` fails during the "Determining the checkout info" |
| 27 | + or subsequent git fetch phase when the repository contains branch names whose path |
| 28 | + components differ only by case — for example, `feature/manu` and `Feature/tarun`. |
| 29 | +
|
| 30 | + The root cause is that Windows uses the NTFS filesystem, which is case-insensitive |
| 31 | + (case-preserving but not case-sensitive). Git stores remote-tracking refs as directory |
| 32 | + structures: `refs/remotes/origin/feature/` and `refs/remotes/origin/Feature/` would |
| 33 | + map to the same directory on Windows. When git attempts to create both, the second |
| 34 | + ref creation fails with a lock error or "cannot create directory" error. |
| 35 | +
|
| 36 | + Linux runners are not affected because Linux filesystems (ext4, etc.) are case-sensitive |
| 37 | + and can store both `feature/` and `Feature/` as distinct directories simultaneously. |
| 38 | +
|
| 39 | + This is ultimately a Git-on-Windows limitation rather than an actions/checkout bug, but |
| 40 | + checkout surfaces it as an opaque error during the checkout phase. The issue affects |
| 41 | + any version of actions/checkout (v4, v5, v6) on Windows runners. |
| 42 | +
|
| 43 | + Common branch naming patterns that trigger this issue: |
| 44 | + - `feature/foo` and `Feature/bar` (mixed case in the directory component) |
| 45 | + - `fix/issue-1` and `Fix/issue-2` |
| 46 | + - `release/v1` and `Release/v2` |
| 47 | +fix: | |
| 48 | + The fix requires changing branch names in the repository to avoid case-only collisions |
| 49 | + in path prefixes. On Windows, two branches cannot coexist if their path components |
| 50 | + are identical when lowercased. |
| 51 | +
|
| 52 | + **Option 1 (recommended):** Rename branches to use a consistent case convention. |
| 53 | + Most teams standardize on all-lowercase branch prefixes: |
| 54 | +
|
| 55 | + git branch -m Feature/tarun feature/tarun-2 |
| 56 | +
|
| 57 | + **Option 2:** Run the Windows CI workflow only after avoiding the fetch of conflicting |
| 58 | + refs using a sparse fetch: |
| 59 | +
|
| 60 | + - uses: actions/checkout@v6 |
| 61 | + with: |
| 62 | + fetch-depth: 1 |
| 63 | + # fetch-depth: 1 avoids fetching all remote refs, which may avoid the collision |
| 64 | +
|
| 65 | + Note: this only helps if the checkout target branch is not itself one of the conflicting |
| 66 | + refs. All remote-tracking refs are still fetched by default. |
| 67 | +
|
| 68 | + **Option 3:** Run Windows CI on Linux or macOS where the case collision does not apply, |
| 69 | + and file a repository convention to standardize branch name casing. |
| 70 | +fix_code: |
| 71 | + - language: yaml |
| 72 | + label: 'Broken: repo has feature/manu and Feature/tarun — fails on Windows' |
| 73 | + code: | |
| 74 | + # This workflow fails on windows-latest when the repo has: |
| 75 | + # branch: feature/manu |
| 76 | + # branch: Feature/tarun |
| 77 | + # Git cannot create both refs/remotes/origin/feature/ and |
| 78 | + # refs/remotes/origin/Feature/ on Windows NTFS. |
| 79 | + jobs: |
| 80 | + build: |
| 81 | + runs-on: windows-latest |
| 82 | + steps: |
| 83 | + - uses: actions/checkout@v6 |
| 84 | + # ERROR on Windows: |
| 85 | + # error: cannot lock ref 'refs/remotes/origin/Feature/tarun': |
| 86 | + # 'refs/remotes/origin/feature' exists; cannot create 'refs/remotes/origin/Feature' |
| 87 | + - language: yaml |
| 88 | + label: 'Workaround: use fetch-depth: 1 to limit which remote refs are fetched' |
| 89 | + code: | |
| 90 | + jobs: |
| 91 | + build: |
| 92 | + runs-on: windows-latest |
| 93 | + steps: |
| 94 | + - uses: actions/checkout@v6 |
| 95 | + with: |
| 96 | + fetch-depth: 1 # fetch only the checked-out commit, not all remote refs |
| 97 | + # This avoids fetching the conflicting case refs from origin. |
| 98 | + # Note: git log history and other branch refs are unavailable. |
| 99 | + - language: yaml |
| 100 | + label: 'Fix: enforce lowercase branch naming convention via branch protection' |
| 101 | + code: | |
| 102 | + # In GitHub repository settings, add a branch name pattern rule that |
| 103 | + # requires all new branches to match a lowercase pattern, preventing |
| 104 | + # future case collisions: |
| 105 | + # |
| 106 | + # Repository Settings → Branches → Branch protection rules → Add rule |
| 107 | + # Branch name pattern: [^A-Z]* (no uppercase letters allowed) |
| 108 | + # |
| 109 | + # To fix existing conflicting branches, rename them: |
| 110 | + # git push origin :Feature/tarun # delete remote branch |
| 111 | + # git push origin Feature/tarun:feature/tarun-v2 # recreate with lowercase |
| 112 | +prevention: |
| 113 | + - "Establish a branch naming convention that disallows uppercase letters in the path prefix component (e.g., always use `feature/`, never `Feature/`)." |
| 114 | + - "Add a GitHub Actions workflow or branch protection rule that rejects branch names with uppercase in the prefix to prevent future case collisions." |
| 115 | + - "Before migrating Windows runners into a repository's CI, audit branch names for case-insensitive prefix collisions using `git branch -r | sort -f`." |
| 116 | + - "If your repository may have case-conflicting branches (e.g., from contributors on macOS/Linux who don't notice), use `fetch-depth: 1` on Windows checkout steps to reduce the risk." |
| 117 | +docs: |
| 118 | + - url: 'https://github.com/actions/checkout/issues/2448' |
| 119 | + label: 'actions/checkout #2448 — checkout fails on Windows when branches differ only by case' |
| 120 | + - url: 'https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt-ltrefspecgt' |
| 121 | + label: 'git-scm.com — git fetch refspec: how remote-tracking refs are stored as directory trees' |
| 122 | + - url: 'https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches' |
| 123 | + label: 'GitHub Docs — Protected branches: enforcing naming conventions' |
0 commit comments