34

As the title states, I'm attempting to pull from a git repository that I'm sharing between my friend and I and I can commit, he can commit, but whenever either one of us attempt to pull it brings back that it failed: DIRTY_WORKTREE

Both of us are extremely new to git, and have zero direction on how to fix this issue.

Ariana
  • 745
  • 3
  • 9
  • 15
  • i am facing same problem, when i try to pull it fails and show message "DIRTY_WORKTREE login". – Dev May 12 '14 at 05:58
  • 3
    could you delete those extra files mentioned in the message? (As I mention in http://stackoverflow.com/a/15476133/6309) – VonC May 12 '14 at 07:03
  • hey @VonC i followed steps as you mention on the above link but it didn't helped me.plz have a look at my problem...link:: http://stackoverflow.com/questions/23602895/best-practice-for-using-egit-with-an-app-engine-connected-android-project-in-ecl – Dev May 18 '14 at 17:31

14 Answers14

15

I was able to fix a similar issue by using the git command line client. While eclipse (egit) was only saying DIRTY_WORKTREE, in the command line I saw multiple conflicting files. Using git merge master from the command line, I could easily resolve the conflicts then in eclipse. So for me this seems to be an egit issue.

Clerenz
  • 821
  • 8
  • 23
13

Another approach, if you don't have any work in progress, is to try and reset --hard your HEAD.

With EGit: Resetting your current HEAD:

Select Team -> Reset... on a project. This opens a dialog where you can select a branch or a tag.

Reset HEAD on your current branch, in order to reset index and working tree to the last commit of said branch.

Then try your pull.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • In case anyone else has a similar issue - I was getting this same error in Eclipse - but not in `SourceTree`. Files had been pushed through `SourceTree`, but on trying to do a pull of the same unmodified files in Eclipse - I was getting the same error. I tried the > team -> reset (Thank you VonC) and things went back to normal! – JGlass Jan 16 '17 at 21:27
  • 1
    In my case, I couldn't neither commit my changes, nor pull changes from repository. As a precaution, first I backed up all changes I made to the project. Then, I did _right click_ > _Team_ > _Reset..._ > selected item in _Remote Tracking_ > selected _Reset type_ **Hard** > _Reset_. After that I needed to get my changes back from the backup, and finally to commit them. – predrags Apr 12 '21 at 14:10
  • @predrags Interesting: don't hesitate to edit the answer and add your solution. – VonC Apr 12 '21 at 14:11
  • @VonC thank you on suggestion, but I don't consider it a solution, it was rather an extension or a special case of your solution. – predrags Apr 12 '21 at 14:25
10

I had uncommitted changes. After I committed them, then merged, the dirty worktree issue disappeared.

ununiform
  • 406
  • 5
  • 6
1

Just delete the .gitignore present in the project folder, and then merge. The merge will show conflicts , which you need to resolve and then push the changes.

abagri
  • 141
  • 1
  • 5
1

It seems to mean that the version you are on now has edits that are not yet committed. So you either have to remove these edits, or commit them. Notice that if you commit them you may get merge conflicts.

noname
  • 11
  • 1
1

This error is happening when you have made local changes to files that haven't been committed yet. In git's parlance, you have uncommitted changes in your working tree.

When you are in this situation and you try to pull, git is not sure what to do with the local changes you have. Should it discard those and pull the changes from the remote? Should it commit those before pulling the changes from the remote? That's why it fails.

To avoid this problem before you pull changes into your local repository you either have to commit your local changes, stash them, or discard them. Once you don't have pending local changes in your working tree, you should be able to pull with no errors.

Pedro
  • 2,300
  • 1
  • 18
  • 22
0

In eclipse I went to Team Synchronizing View and from there right clicked on my project and hit 'overwrite' to overwrite all local changes. Then retry your merge.

osoblanco
  • 468
  • 2
  • 10
0

Only to add another case, I've got DIRTY_WORKTREE, I'm the only one commiting to my Github project, so in EGit I did a Push branch... with "Force overwrite of branch on remote if it exists and has diverged"

DANGER: If other are working on the same project, this action will delete their commits since divergence.

Alejandro Silvestri
  • 3,706
  • 31
  • 43
0

I had similar problem on Eclipse with uncommited changes as ununiform. After a commited I could merge and everything is back as it should be. Take a look at your source code and check any changes. If none you can reset hard.

0

Delete the affected files and try to pull again. Thereafter push your changes to the git. I has the same issue and this worked for me.

vennapu
  • 45
  • 7
0

In my case, the DIRTY_WORKTREE was caused by this sequence:

  1. In a commit, I committed also some files that I should have ignored
  2. In the next commit I modified the .gitignore that ignore the above files
  3. Try to rebase on top of another branch where my change to .gitignore is missing

In this scenario, Eclipse thinks your working tree is dirty. Indeed, it is not obvious comparing two filesets when one of the two is ignoring some files and the other is not.

To solve the issue in Eclipse, I did the following:

  • Modify the .gitignore so it is the same as the one in the branch I want to rebase on
  • Happily start the rebasing or rebasing with merge.
psuzzi
  • 2,187
  • 1
  • 17
  • 21
0

If you have changes without commiting, eclipse will advise you if you try to pull changes. To solve it, you can discard the changes or do the commit of these files.

Source: https://www.eclipse.org/forums/index.php?t=msg&th=890477&goto=1565668&#msg_1565668

0

If you want to override you local branch to the origin branch.

Go to Git repo view> click on origin master> Choose reset ->it will show current HEAD and resetting to branch. Choose HARD reset, if you want to completely overwrite your local changes

LadyQ
  • 9
  • 2
-2

I think this problem is caused by EGit version. When I used Spring Tools Suite with EGit 2.6, I also faced same problems.

EGit is included in STS Default package, so EGit upgrade is very difficult.

Currently I am using eclipse WTP with EGit 3.7, this problem is disappeared.