1

On my staging server I have a cron job that does a git pull every two minutes, most of the times everything works fine, but sometimes I notice that the changes that I pushed to the repo are not pulled, when I inspect the issue and run git pull manually I get an error:

error: Your local changes to the following files would be overwritten by merge:
{the file(s) that I had pushed to the repo}
Please, commit your changes or stash them before you can merge.

I don't understand how these changes are being considered "local changes". any help?

Khalid Dabjan
  • 2,697
  • 2
  • 24
  • 35
  • it seems that you have accidentally edited a file on your server. I would suggest verify the changes first using `git diff` then if you don't want the changes on the server you can do `git stash` – Zeeshan Abbas Mar 21 '15 at 10:11
  • This happened several times, and the local changes are always my latest commit. – Khalid Dabjan Mar 21 '15 at 10:13
  • is it some specific file that it refers to every time it gives that error ? Also have a look at a [similar thread](http://stackoverflow.com/questions/14318234/ignoring-your-local-changes-to-the-following-files-would-be-overwritten-by-merg) – Zeeshan Abbas Mar 21 '15 at 10:37

1 Answers1

0

I mentioned before ("Cannot pull with rebase") that git rebase learned the --autostash option (git 1.8.5+).

You could combine that with a reset --hard in order to make sure the end result of your scheduled git upll is always a clean state:

git config rebase.autostash true
git pull -rebase
git reset --hard

That assumes you have no local commit or work in progress on the repo updated by your git pull (or it would be erased by the reset --hard)

The autostash option ensure that the untracked state of the working tree (for whatever reason) is not blocking the git pull.
And the reset --hard should make sure the working tree is clean.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250