Software⏱️ 3 min read📅 2026-06-03

How to Fix: fatal: git-write-tree: error building trees

Git error fixing guide.

Quick Answer: Try a force push with git push -f origin master to overwrite the changes.

The 'fatal: git-write-tree: error building trees' error occurs when Git is unable to build a new tree during the checkout process. This can happen due to conflicts in the repository, missing files, or other issues that prevent Git from creating a valid tree.

This error affects users who have attempted to pull changes from a shared repository and then tried to revert changes using 'git revert'. The frustrating part is that it may not be immediately clear what went wrong, as the error message does not provide specific details about the conflict or issue.

🛑 Root Causes of the Error

  • The primary reason for this error is conflicts in the repository. When Git tries to pull changes from a shared repository, it may encounter conflicts between different versions of files. If these conflicts are not resolved before attempting to revert changes, Git will fail to build a new tree.
  • Another possible cause is missing files or directories in the repository. If a file or directory is missing, Git will not be able to create a valid tree, resulting in this error.

🔧 Proven Troubleshooting Steps

Resolving Conflicts using git stash and git checkout

  1. Step 1: First, use 'git stash' to temporarily remove the changes from your working directory.
  2. Step 2: Next, use 'git checkout --theirs ' or 'git checkout --ours ' to resolve any conflicts in the file. Replace '' with the name of the conflicting file.
  3. Step 3: If there are multiple files with conflicts, you may need to repeat this step for each file. Once all conflicts have been resolved, use 'git stash apply' to reapply the stashed changes.

Reverting Changes using git revert

  1. Step 1: Try to revert the changes using 'git revert '. Replace '' with the hash of the commit that caused the error.
  2. Step 2: If the above method fails, try to use 'git revert --abort' to cancel the revert operation and start again from a clean state.

💡 Conclusion

To resolve the 'fatal: git-write-tree: error building trees' error, first identify and resolve any conflicts in the repository. If conflicts are not present, check for missing files or directories that may be preventing Git from creating a valid tree. If none of these solutions work, try reverting changes using 'git revert'. Remember to always backup your repository before making significant changes.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions