Git can't push commit - DIRTY_WORKTREE Git Error

Question:
I have a whole set of edits that appear stuck as a commit, unable to push to git, or even get back to view. I created the commit with all the edits, and switched to view main. Then when I try to switch back to that branch, I get:
Git Error DIRTY_WORKTREE
There are uncommitted changes.

I can dismiss this, but I can’t see the changes in my commit anymore b/c I can’t open that branch (opening that branch is blocked by the error).

Trying it manually doesn’t work. I used

git push --force
Everything up-to-date

so i tried

git push origin <branch-name>

and it shows it there when i go look in github on the web, but replit seems confused, and now shows two branches, and clicking either one throws the same error.

Screenshots, links, or other helpful context:

image

Here’s what it shows in git menu:

image

Try committing your changes first, via the shell: git commit -m "commit message"

3 Likes

Hi @codymtaylor,
I can help you better if you type in your command line:
git status
and share with us, the result in the promt so we can know exactly
the current status to do what is necessary to push your branch.

Thanks @julioaranajr. SOLVED - see below.

When I use

git status

I get

$ git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

I just want to switch back to my server-db branch, but can’t do so in replit git tool.

However, I used

get checkout server-db

And it appears to have cleaned up the DIRTY_WORKTREE, because I can now switch between main and server-db branch without errors. The Replit git tool still shows a second origin/server-db, but i used the replit git tool again and selected ‘push to remote’ for origin/server-db. this seems to have all pieces correctly back in sync again.

I don’t know what caused the DIRTY_WORKTREE in the first place, so not sure how to reproduce or avoid in future. It seemed like it happened when i used the replit git tool to push changes to a branch on github, then switched to main right afterward. Speculation: perhaps the push operation had not finished and replit did not allow it to finish before pulling main.

1 Like