24

So at work we all share the same stash were we push and pull our branches and all that good git stuff. So i usually do my pull and push from egit in eclipse (I am not the only one most people here do it this way). but some of my branches have started giving me the [lock fail] "couldn't lock local tracking ref for update". But the thing is there are 75+ people doing it the same way and no one has seen this error. I have done some research and most of it says it is based off name conflicts for example Foo and foo. Egit would get confused on which one to pull because the only difference is a capital letter, but other people are having no issues. I don't know what is going on. Any help would be greatly appreciated.

dabezt
  • 251
  • 1
  • 2
  • 4
  • you should provide a concrete Stack Trace (open Error Log, double click on a Message and c&p) – Gambotic Apr 16 '18 at 15:05
  • See https://bugs.eclipse.org/bugs/show_bug.cgi?id=417860#c3 – howlger Apr 16 '18 at 15:23
  • This is all when i try and pull in egit so it doesnt update the error log. I am not sure where to find any sort of error message to help out – dabezt Apr 16 '18 at 15:24
  • [_"Check if you have any ".lock" file under .git/refs/"_](https://bugs.eclipse.org/bugs/show_bug.cgi?id=417860#c3). Which EGit version do you use? The current version is 4.11 (update site: `http://download.eclipse.org/egit/updates`). – howlger Apr 16 '18 at 15:28
  • 1
    Git is updated and there is a lockfile under eclipse -> workspace -> .metadata. but every time i delete it and reboot eclipse it just comes back. – dabezt Apr 16 '18 at 15:39
  • You have to search for lock files in the `git/refs` folder in your Git repository folder, not in the workspace `.metadata` folder (which also contains a lock file but for other purposes). – howlger Apr 17 '18 at 07:21

10 Answers10

31

I could neither fetch nor push nor rebase, and got a "lock fail" error in eclipse too.

The solution I found was to open git bash, go to git folder, then do a git fetch. After this I was able to rebase and push with eclipse.

You can also check in your eclipse preferences/team/git/configuration that you have not set fetch.prune=true because it may cause this problem.

RotS
  • 2,142
  • 2
  • 24
  • 30
21
git remote prune origin

solved it for me.

Arash Kamangir
  • 293
  • 3
  • 7
  • thank you. worked like a charm, running antergos + eclipse 2019-06. – mercredo Jul 31 '19 at 12:39
  • Hmm, this worked initially, but then the next egit pull said I was ahead of origin/master. git push from command or eclipse gets me in sync with origin/master, but then the next egit pull goes back to being ahead of origin/master – David Wood Feb 20 '20 at 20:11
7

I've seen this a couple times in Eclipse 2019-06 now. Possibly related to tag-creation as it seems to have occurred recently after those events. In any event, I think if you close Eclipse, and delete eclipse-workspace/.metadata/.lock file (and possibly eclipse-workspace/.metadata/.log) it gets better on restart.

Jeff Bennett
  • 996
  • 7
  • 18
  • Issues with 2019-06 are tracked by https://bugs.eclipse.org/bugs/show_bug.cgi?id=548716 – Pyves Jul 18 '19 at 18:23
4

It´s simple.

1 - Close Eclipse IDE; 2 - Go to the project directory; 3 - Type: git pull; 4 - Type: git gc; 5 - Reopen the Eclipse IDE; 6 - Pulling the project;

Always works for me!

3

The issue for me was that I had a bunch of branches that I had pulled as feature/somename but when I pushed it to remote, they appeared as Feature/somename. Once I solved this f to F issue, things started working as expected.


Prune using EGIT

Also, if you want to prune the repository, you should use GIT GC in order to achieve this. EGIT has an option called Collect Garbage to trigger this. Simply, right click on the repository in the EGIT perspective to see this option.

Taha
  • 59
  • 7
  • I renamed the folder name from F (uppercase) to f (lowercase) to get rid of the "f to F" issue. – Taha May 30 '20 at 14:09
2

For me, I encountered the lock fail problem in tags, so I do following steps:

  1. Reset current branch
  2. Delete all local tags.
  3. Fetch
  4. Pull. It solves the problem.
2

For the others : I had this error too, and that was because I had 2 branches on the repo with similar names ("v10" and "V10"). I fixed it by "renaming" the repo branch "V10" (i.e. creating another "V10b" from "V10", then deleting "V10").

pierreonthenet
  • 155
  • 1
  • 12
  • I have heard of developers in our organization getting this error, and I believe that this situation you describe is the cause of it. The Windows DOS filesystem is case-insensitive, so it thinks that "v10" and "V10" are the same thing, but git does not. I wrote a script to detect these situations, using "uniq -d". – David M. Karr Jul 16 '21 at 13:48
2

in eclipse right Click in Project

  • team >remote> Configure fetch for Upstream>
  • Advanced> selecte in ‘source ref’ and ‘destination ref’ your branch
  • Click ‘Add Spec’
  • Check the Force update> Finish >Save and Fetch
Amirouche Zeggagh
  • 3,428
  • 1
  • 25
  • 22
1

I used Arash's

git remote prune origin

But this left me with a situation in which an egit pull put me way ahead of the remote/origin. An egit or git push brought be back in sync, but then the next egit pull put me ahead again. To fix that, I tried various thing including Resetting the repo, but to no avail. This is probably similar to starting with a new workspace, but in my case that was not an option. The following seems to have worked:

  1. Make sure you have pushed all changes to the remote repo.
  2. In the Project Explorer view, delete all projects that have been imported into eclipse from the repository in question. Don't delete files in the file system (check box in dialog box that pops).
  3. In the Repositories view, right click on repository and Remove Repository From View
  4. At the command line. move or delete the root of the git repo.
  5. Back to Eclipse and add the repository (in the Repository View, paste the URL/ssh link as copied from github).
  6. Re-import the desired projects into Eclipse by right-clicking on the repo and selecting Import Projects...

Ugly but does the trick.

David Wood
  • 434
  • 1
  • 5
  • 14
0

I've seen this happen in Windows, because the underlying DOS filesystem is case-insensitive, although git is not. When git writes a file named "foo", Windows thinks that the attempt to write the file "Foo" is writing to the same file. I don't know the exact mechanism that creates the "lock fail" error, but I assume it is something like this.

I wrote a script to detect this situation. Our SCM is BitBucket, which has a REST api. I use the "projects/repos/branches" endpoint in a loop to get all the branches from a repository, execute the following pseudocode:

echo $list | tr '[:upper:]' '[:lower:]' | sort | uniq -d

The result is a list of the branch names, converted to lowercase, that have two or more versions, varying by case.

David M. Karr
  • 14,317
  • 20
  • 94
  • 199