Error Building Trees in Git: Permissions, Bamboo Cache, or Stash
Git stopped your commit, stash, or Bamboo build on “fatal: git-write-tree: error building trees”. That last line names no file and no reason, only that the tree couldn’t be built.
The short answer
As of November 2026, the sources document three causes of “Error building trees,” so read the line printed just above it. A permission message points to .git/objects, a missing cache directory points to the Bamboo repository cache, and needs merge points to an unresolved conflict during git stash.

For the permission message from git commit, fix the permissions on the affected files in .git/objects.
The error
Error building trees
Error: invalid object
Error: object directory [...] does not exist
fatal: git-write-tree: error building trees
This is an example, reconstructed from the messages a failing Bamboo Repository Commit task writes to its log, with the paths shortened. Your exact lines and order will differ.

The same final error also shows up on a plain git commit or git stash. The last line is identical in every case, so the lines above it are what you compare against your own log.
How to fix it
1. Match the line above the error to a cause
| Line above the error | Cause | Go to |
|---|---|---|
insufficient permission for adding an object to repository database .git/objects |
Wrong permissions in .git/objects |
Steps 2 and 3 |
object directory .../_git-repositories-cache/.../.git/objects does not exist or invalid object for '.gitignore' |
Bamboo repository cache (Data Center) | Steps 4 and 5 |
CHANGELOG.md: needs merge or unmerged during git stash |
Unresolved conflict | Step 6 |
If your log matches none of these, stop here. The steps below only cover these three patterns.
2. List .git/objects to find the bad entries
This applies when git commit fails with the permission message:
error: insufficient permission for adding an object to repository database .git/objects
error: Error building trees
List the object directory with sizes and owners:
ls -lah .git/objects
Compare the owner and permission columns across entries. In the example this fix comes from, a folder such as 6c shows up as root:root, while the other entries belong to the user. Any entry that looks like that needs fixing.
3. Change the owner or permissions of the flagged entries
For every entry you flagged in step 2, such as a root:root folder, change its ownership or permissions so your own user can read and write it. The source for this fix says only that changing the permissions makes the error go away. It gives no exact command, so I won’t write one here.

Then run git commit again. If the permission line is gone but the error remains, re-read the line above it. You may be in a different case.
4. Clear the cache in Manage caches (Bamboo)
This applies to a failing Repository Commit task in Bamboo. Atlassian’s KB documents it for Bamboo Data Center only (as of November 2026). The matching log lines point at the _git-repositories-cache directory on the Bamboo server.

In Bamboo, go to:
Cog icon > Overview > Repository settings > Manage caches
Delete the respective cache for the failing repository, then re-run the build. This is the first method the KB lists.
5. Remove the repository from the plan and re-add it
If the build still fails after clearing the cache, take the repository out of the build plan and add it back. The KB lists this as the second workaround, so treat it as the fallback.
Then re-run the Repository Commit task and check whether the line above the error has changed.
6. Resolve the conflicted file before you stash again
This applies when the error shows up during git stash after a modify/delete conflict on CHANGELOG.md. In the reported case, the log shows these lines in this order. The line in brackets is described, not quoted, because the exact wording varies:
[git stash pop reports a modify/delete CONFLICT on CHANGELOG.md]
CHANGELOG.md: needs merge
CHANGELOG.md: unmerged (...)
error: [ui] `git stash push --include-untracked -m !!GitHub_Desktop<aaa>` exited with an unexpected code: 1.
fatal: git-write-tree: error building trees
Cannot save the current index state
That is an observation about the log, not a proven chain of cause and effect. The material for this case documents the symptoms only. It does not include a confirmed fix.
Cleaning up the conflicted CHANGELOG.md first is the reasonable move, since it is the file git reports as needing a merge. But nothing confirms that resolving it makes the error go away. Check the exact commands against the official git documentation before you run them.
The GitHub_Desktop text in the command suggests a GUI client was driving the stash, though the client isn’t confirmed.
Why this happens
“Error building trees” is the same text in all three cases, so the message alone can’t tell you why it failed. Only the lines printed above it can.
- Permissions: Some files inside
.git/objectslack read or write permission for your user. - Bamboo cache: Atlassian’s KB says the failure is usually caused by a corrupted repository cache (Bamboo Data Center, as of November 2026).
- Stash: The logs list
CHANGELOG.mdasneeds mergeandunmerged, and the error follows. The sources document that order, but they don’t explain the mechanism.
Common mistakes
Fixing one
root:rootfolder and stopping. In the example listing, subdirectories such as6cwere owned byroot:rootinstead of the userygpark. Check every entry inls -lah .git/objectsbefore you retry the commit.Retrying the stash before settling the conflict. After
CONFLICT (modify/delete)onCHANGELOG.md, the stash ends withCannot save the current index state. Decide whetherCHANGELOG.mdstays or goes first, then stash again.Jumping to the fallback in Bamboo. Clear the cache in Manage caches first. Remove and re-add the repository only if the build still fails, since the KB lists it as the second workaround.
FAQ
Q. Will the Bamboo cache fix work on Bamboo Cloud or Server? A. The Atlassian KB article is marked Data Center only (as of November 2026). I have no source confirming the same menu path or fix on other Bamboo editions, so check Atlassian’s docs for your edition before relying on it.
Q. What if ls -lah .git/objects shows nothing odd? A. Then the permission cause probably doesn’t apply to you. Go back and re-read the line printed above the error.
Q. What if clearing the cache and re-adding the repository both fail in Bamboo? A. My sources stop after those two workarounds, so I can’t give you a third verified fix. Read the build log again and check whether the line above the error still mentions the _git-repositories-cache path or has changed to something else.
Recap
- Match the line above “Error building trees” to its cause:
.git/objectspermissions, a Bamboo cache problem, or an unresolved stash conflict. - Permissions: list
.git/objectswithls -lahand fix any root-owned entries so your user can read and write them. - Bamboo (Data Center only): clear the cache in Manage caches first, then re-add the repository. For stash, resolve CHANGELOG.md before retrying.
Sources
This article was created using generative AI based on publicly available sources.