This error occurs during a Git merge or rebase when a file was renamed in one branch but deleted in another. Git cannot automatically resolve this conflict because it involves a structural change to the file tree, not just content differences. You must manually decide whether to keep the renamed file or accept the deletion.
The "CONFLICT (rename/delete)" message indicates that Git detected a file was renamed in one branch (typically HEAD/your current branch) while the same original file was deleted in the branch you're trying to merge. This is a tree-level conflict rather than a content conflict. Git's rename detection identified that the file was moved or renamed (based on content similarity), but since the other branch removed the original file entirely, Git cannot automatically determine what you intended. The conflict essentially asks: "Should this file exist with its new name, or should it be gone?" This type of conflict commonly occurs when: - One developer refactors and renames files while another removes obsolete code - A file is moved to a new location in one branch while considered unnecessary in another - Concurrent cleanup efforts result in one branch renaming for organization and another deleting for simplification
When you see:
CONFLICT (rename/delete): file.txt renamed to newfile.txt in HEAD, but deleted in branchThis means:
- In HEAD (your current branch): file.txt was renamed to newfile.txt
- In the incoming branch: file.txt was deleted
Git is asking you to decide: keep newfile.txt or accept the deletion?
Check the current state:
git statusYou'll see something like:
Unmerged paths:
(use "git add/rm <file>..." as appropriate to mark resolution)
deleted by them: newfile.txtIf you want to keep the file with its new name, stage it with git add:
# Keep the renamed file
git add newfile.txtThis tells Git: "I want to keep this file with its new name, ignoring the deletion from the other branch."
After staging, verify the resolution:
git statusYou should see the file listed under "Changes to be committed" rather than "Unmerged paths".
If you agree that the file should be deleted, use git rm:
# Accept the deletion
git rm newfile.txtThis tells Git: "I agree the file should be removed, the rename in my branch was a mistake or is now obsolete."
Verify the resolution:
git statusThe file should now appear as deleted and staged for commit.
After resolving the conflict (either keeping or deleting), complete the merge:
git commitGit will open your editor with a merge commit message. You can add a note about how you resolved the conflict:
Merge branch 'feature' into main
Resolved rename/delete conflict:
- Kept newfile.txt (renamed from file.txt)Save and close the editor to finalize the merge.
Sometimes the conflict is reversed:
CONFLICT (rename/delete): file.txt deleted in HEAD and renamed to newfile.txt in branchThis means you deleted the file, but the incoming branch renamed it.
To keep the renamed file from the incoming branch:
git checkout --theirs newfile.txt
git add newfile.txtTo confirm the deletion:
git rm newfile.txtThen complete the merge with git commit.
For more control, you can use git checkout with --ours or --theirs:
Keep your version (the renamed file):
git checkout --ours newfile.txt
git add newfile.txtAccept their version (deletion):
git rm newfile.txtNote: The meaning of "ours" and "theirs" can be confusing during rebases, where they are reversed. During a rebase:
- --ours refers to the branch being rebased onto
- --theirs refers to your commits being replayed
If you're unsure or want to start over, you can abort the merge:
git merge --abortFor a rebase conflict:
git rebase --abortThis returns your repository to the state before the merge/rebase began, allowing you to:
- Communicate with your team about the conflict
- Rename the file in your branch to match the other branch first
- Plan a better merge strategy
To avoid rename/delete conflicts:
Before major refactoring:
# Pull latest changes first
git fetch origin
git merge origin/mainCommunicate structural changes to your team when:
- Renaming files or directories
- Deleting files or modules
- Reorganizing project structure
Keep branches short-lived to minimize divergence:
# Regularly sync with main
git fetch origin
git rebase origin/mainReview incoming changes before merging:
git fetch origin
git log HEAD..origin/main --name-statusThis shows what files changed in the incoming branch, helping you anticipate conflicts.
Understanding Git's rename detection
Git doesn't explicitly track renames. Instead, it detects renames by comparing file content similarity. By default, Git considers files with >50% similar content as renames. You can adjust this:
# Set rename threshold to 70% similarity
git merge -X rename-threshold=70 feature-branch
# Disable rename detection entirely
git merge -X no-renames feature-branchUsing git show to understand the conflict
View what each branch did to the file:
# See the state of the file in HEAD
git show HEAD:newfile.txt
# See if the file existed in the merge base
git show $(git merge-base HEAD feature-branch):file.txtApplying patches for complex renames
When you have changes in the deleted file that need to be applied to the renamed location:
# Generate a patch from the deleted file's changes
git show MERGE_HEAD -- file.txt > changes.patch
# Apply to the renamed file (with manual adjustment if needed)
patch newfile.txt < changes.patchThe REBASE_HEAD trick
During rebases, you can apply changes from the conflicting commit to renamed files:
git show REBASE_HEAD path/to/old-file.txt | patch path/to/new-file.txtGit rerere for repeated conflicts
If you encounter the same rename/delete conflicts repeatedly, enable rerere:
git config --global rerere.enabled trueGit will remember your resolutions and apply them automatically next time.
Merge strategies for structural conflicts
Consider using the recursive strategy with specific options:
# Favor your changes in conflicts
git merge -X ours feature-branch
# Favor their changes in conflicts
git merge -X theirs feature-branchNote: These options apply to conflicting hunks, not the entire file. For rename/delete conflicts, you still need to manually decide using git add or git rm.
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server
fatal: unable to access: Proxy auto-configuration failed
How to fix 'Proxy auto-configuration failed' in Git
fatal: unable to access: Authentication failed (proxy requires basic auth)
How to fix 'Authentication failed (proxy requires basic auth)' in Git
fatal: unable to access: no_proxy configuration not working
How to fix 'no_proxy configuration not working' in Git
fatal: unable to read tree object in treeless clone
How to fix 'unable to read tree object in treeless clone' in Git