grautur
grautur

Reputation: 30505

Troubles with git and Gemfile.lock

I keep running into the following error with my Gemfile.lock whenever I want to do a git pull or checkout a new branch.

error: Your local changes to the following files would be overwritten by merge:
    Gemfile.lock
Please, commit your changes or stash them before you can merge.
Aborting

The problem is that I can't figure out how to fix it.

What do I need to do? I've gone so far as to just clone a new git repo, but soon enough, all this starts happening again.

Upvotes: 47

Views: 13718

Answers (5)

user22029208
user22029208

Reputation:

I had this issue as well and I got it working by disabling Ruby LSP extension on VSCode. Then I was finnally able to merge the main branch to my feature branch.

Upvotes: 1

Tadesse Alemayehu
Tadesse Alemayehu

Reputation: 1

I had the same issue.

for me, rebasing the branch works. git rebase origin "remote-branch"

Upvotes: 0

V K Singh
V K Singh

Reputation: 1254

You are not able to checkout Gemfile.lock since spring is running in the backend to sync your code in developement environment. If you want to checkout, firstly stop the spring processes. You can stop spring in two different ways.

  1. Either you just stop spring using command in the terminal

spring stop

  1. Or by manually killing the processes of spring running on local, just like

    ps -aef | grep spring
    kill -9 pid
    

Both looks good to me. Choose what's better for you!

Upvotes: 3

Tristan Havelick
Tristan Havelick

Reputation: 69398

This happened to me and git reset --hard HEAD from the accepted answer didn't help. However, running spring stop did the trick. I suspect spring is rewriting the file whenever it is modified to ensure that it is in sync with the code running via spring.

Upvotes: 111

frediy
frediy

Reputation: 1766

After doing the following, I was able to pull and check out branches again.

git checkout Gemfile.lock
git reset --hard HEAD

I'm not sure why and how this solution works. Explanations are welcome.

The reason git was detecting Gemfile.lock as modified in my case, was that the bottom of the file had BUNDLED WITH 1.10.3. After updating bundler gem update bundler, regenerating and committing Gemfile.lock, it stopped appearing in git as modified.

git version 2.2.1, Mac OSX version 10.10.4, iTerm2 Build 2.9.20150624-nightly (w/shell integration)

Upvotes: 9

Related Questions