329 字
2 分鐘
Git fetch/pull Failing? Complete Solution for Case-Sensitive Branch Conflicts
Conclusion
- Use commands to find case-sensitive conflicts → keep one → delete redundant branches, and you can resolve Git fetch/pull failures.
Applicable Scenarios
- Windows / Mac developers encountering Git pull failures
- Teams using a mix of Linux + Windows
- Lack of unified branch naming conventions
- CI/CD suddenly unable to find branches
Step-by-Step Process
1. Identify Case-Sensitive Conflict Branches
- Use
git ls-remoteto fetch remote branches, convert them to lowercase, and then group and compare. - The core idea is to find branches with “different names but identical after converting to lowercase”.
git ls-remote --heads origin |ForEach-Object { ($_ -split "`t")[1] } |Group-Object { $_.ToLower() } |Where-Object { $_.Count -gt 1 } |Select-Object -ExpandProperty Group👉 This step is crucial; conflicts cannot be resolved if not identified.
2. Decide Which Branch to Keep
- Usually standardize to lowercase (e.g.,
feature/login) - Or decide according to team conventions 👉 Git is case-insensitive on Windows, so only one can be kept.
3. Delete Redundant Branches
- Delete conflicting remote branches
git push origin --delete Feature/Login- Remember to synchronize local after deletion
git fetch --prune👉 prune is very important, otherwise old data will remain locally.
Additional Notes
- Windows / Mac default to case-insensitive file systems, while Linux is case-sensitive → source of conflict
- It is not recommended to use the
reftablesolution, as tool support is still unstable. - If CI/CD is tied to the wrong branch, confirm the pipeline before deleting.
Command / Example Summary
Click to expand
# 找出大小寫衝突git ls-remote --heads origin |ForEach-Object { ($_ -split "`t")[1] } |Group-Object { $_.ToLower() } |Where-Object { $_.Count -gt 1 } |Select-Object -ExpandProperty Group# 自訂 functionfunction Find-GitCaseConflict { git ls-remote --heads origin | ForEach-Object { ($_ -split "`t")[1] } | Group-Object { $_.ToLower() } | Where-Object { $_.Count -gt 1 } | Select-Object -ExpandProperty Group}# 刪除遠端分支git push origin --delete Feature/Login
# 清理本地git fetch --pruneWrap-up
- Inconsistent Git branch casing is a ticking time bomb.
- It is recommended to standardize naming (all lowercase) from the beginning to avoid many pitfalls later.
Git fetch/pull Failing? Complete Solution for Case-Sensitive Branch Conflicts
https://joyceowo.github.io/posts/en/334a78ea09fa80a889fbf092a1576c5e/