867

How do I ignore the following error message on Git pull?

Your local changes to the following files would be overwritten by merge

What if I want to overwrite them?

I've tried things like git pull -f, but nothing works.

To be clear, I only want to overwrite specific changes, not everything.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mae
  • 14,947
  • 8
  • 32
  • 47
  • Related but no duplicate: http://stackoverflow.com/questions/52704/how-do-you-discard-unstaged-changes-in-git – Daniel Hilgarth Jan 14 '13 at 12:21
  • 12
    @BrianKnoblauch totally agree! Plus, it's not much of a 'merge' if it's 'overwriting' is it? I miss SVN every day... – user1944491 Jun 11 '15 at 13:59
  • 5
    `git config core.fileMode false` save my times – Nolwennig Apr 03 '17 at 12:41
  • 8
    Possible duplicate of [How do I resolve git saying "Commit your changes or stash them before you can merge"?](https://stackoverflow.com/questions/15745045/how-do-i-resolve-git-saying-commit-your-changes-or-stash-them-before-you-can-me) – TylerH Jul 14 '17 at 19:14
  • What if I don't want to overwrite them? – Philip Rego Jul 09 '19 at 20:24

39 Answers39

639

If you want remove all local changes - including files that are untracked by git - from your working copy, simply stash them:

git stash push --include-untracked

If you don't need them anymore, you now can drop that stash:

git stash drop

If you don't want to stash changes that you already staged - e.g. with git add - then add the option --keep-index. Note however, that this will still prevent merging if those staged changes collide with the ones from upstream.


If you want to overwrite only specific parts of your local changes, there are two possibilities:

  1. Commit everything you don't want to overwrite and use the method above for the rest.

  2. Use git checkout path/to/file/to/revert for the changes you wish to overwrite. Make sure that file is not staged via git reset HEAD path/to/file/to/revert.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
  • Possibility #2 does not work. After executing the command nothing happens. On pull I still get the same error. – mae Jan 14 '13 at 13:54
  • 1
    @user1132363: It works for me. Please test it first with a single file. Also, you have make sure that the file you want to overwrite is not staged. – Daniel Hilgarth Jan 14 '13 at 13:58
  • 3
    The trick was to use `git checkout HEAD^ path/to/file/to/revert`. Using **HEAD^** made all the difference. – mae Jan 14 '13 at 14:05
  • 2
    @user1132363: That checks out the previous version and not the one currently checked in. I don't believe that this is the correct approach. – Daniel Hilgarth Jan 14 '13 at 14:05
  • 2
    What if I am not able to do a stash because I have no changed files in my working copy? I get the error message despite having no local changes. – Micah Walter Sep 03 '14 at 15:45
  • 2
    I don't *have* any unstashed local changes and I still got this error. – jpmc26 Mar 05 '15 at 19:34
  • 1
    I had to leave out "`save --keep-index`". – Peter Mortensen Apr 22 '18 at 11:57
  • I still get an error: **Please commit your changes or stash them before you merge. Aborting** – IgorGanapolsky Aug 29 '18 at 10:26
  • Make it just not overwrite the changes. – Philip Rego Jul 09 '19 at 20:24
  • The manual suggests that `save` option is deprecated: `This option is deprecated in favour of git stash push. It differs from "stash push" in that it cannot take pathspecs, and any non-option arguments form the message.` – Dr_Zaszuś Jan 20 '20 at 13:05
  • Why do you add `save --keep-index`? I went `git stash --help` to try and understand but I am none the wiser, particularly as the stash is due to be dropped immediately afterwards. I'd really like to understand what that's about! – mike rodent Mar 07 '20 at 19:48
  • @mikerodent: I have taken your comment as an opportunity to update the answer. Please check. – Daniel Hilgarth Mar 08 '20 at 09:45
  • @mikerodent: Thanks for the hint. I missed `push`. Fixed. – Daniel Hilgarth Mar 08 '20 at 10:21
  • It wasn't a hint, I'm a very low level git person! I just looked at `git stash --help`. From that, it *appears* that the option `--keep-index` belongs with the "sub-command" (if that's what it is) `git stash save`. But this is beyond my pay grade! – mike rodent Mar 08 '20 at 10:40
  • @MicahWalter did you find a solution, got the same issue. – Timo Jan 29 '21 at 19:47
  • 1
    @Timo I don't remember one, I'm sorry :( – Micah Walter Feb 02 '21 at 14:42
  • It's not a good enough solution. We need a way (or script) to take all these files, and ONLY these files that git warns about, and then for each do "git checkout file" if it is in index, and if not do "rm file" and only then do the git pull. That would be an ideal solution. – Nathan B Feb 24 '23 at 14:35
444

This works for me to override all local changes and does not require an identity:

git reset --hard
git pull
kravits88
  • 12,431
  • 1
  • 51
  • 53
  • 3
    This is the easiest solution if you just want to start over and make your `git pull` work. – mikey Dec 11 '20 at 16:39
  • This does not work if a file is not tracked and `git pull` complained about the file since future commits have added a file with same filepath – Sad Pencil Mar 28 '23 at 06:35
424

Alright with the help of the other two answers I've come up with a direct solution:

git checkout HEAD^ file/to/overwrite
git pull
mae
  • 14,947
  • 8
  • 32
  • 47
  • 14
    This worked for me. Could you expand on this answer, ie. what is this actually doing? – cdcdcd Aug 22 '13 at 02:18
  • 4
    It's dropping local changes, reverting to the HEAD reference which is probably the last commit in the master branch – k3a Sep 10 '13 at 17:45
  • 38
    why HEAD^ instead of HEAD? – Yura Nov 13 '14 at 12:59
  • 24
    HEAD^ is short for HEAD^1, which essentially means the one commit before HEAD. You could also do HEAD^2 for the commit before that one. For more information see http://git-scm.com/book/en/v2/Git-Tools-Revision-Selection#Ancestry-References and http://stackoverflow.com/questions/1955985/what-does-the-caret-character-mean. – davidneedham Jul 06 '15 at 20:53
  • 10
    please explain what this does in the answer – endolith Feb 19 '16 at 00:58
  • 1
    This solution was only one working for me when i had a file with --assume-unchanged that was never shown in the changes to be commited so i could not stash it. Really good solution!. – Faito Oct 05 '17 at 13:40
  • 1
    After doing this, it said "You are in 'detached HEAD' state." and I found myself in state where `git pull` now says "You are not currently on a branch. Please specify which branch you want to merge with.". I gave up and restored from backup where I did not have the unwanted changes. :( It really should not be this difficult. – JonBrave Nov 13 '17 at 09:07
  • In my case it, didn't work. But: git checkout HEAD -- my-file.txt worked for me. – Lukas Coorek Sep 10 '21 at 08:13
125

So many answers here that I hate to add yet another, but all of the above are clunkier than they need to be. I have to do this all the time as Git seems to become confused and says I have modified files that have not changed (can't revert because they didn't change, but I can't pull because they supposedly have changed) Simplest and fastest I've found so far is:

git stash
git stash drop
git pull

NOTICE: local changes will be lost

Eugen Konkov
  • 22,193
  • 17
  • 108
  • 158
Brian Knoblauch
  • 20,639
  • 15
  • 57
  • 92
  • 6
    Hm... Dangerous advice. After `stash and drop` you will loose your local changes =( – Eugen Konkov Jul 03 '20 at 11:27
  • 9
    @EugenKonkov That's the whole point... Git sees things as local changes that aren't really changes we want to be kept and we've made no changes that need to be kept. This way you can quickly toss *all* local changes and then move on! – Brian Knoblauch Jul 04 '20 at 14:25
  • @jimsmith Since tossing local changes is the whole point of this, I still struggle with that last part really being necessary at all! – Brian Knoblauch Jul 15 '21 at 10:39
  • 1
    I am not keeping any local changes so this works perfectly (and efficiently) for me so I can pull. – KYLO Jan 17 '23 at 16:10
  • This does not work if a file is not tracked and `git pull` complained about the file since future commits have added a file with same filepath – Sad Pencil Mar 28 '23 at 06:35
81

Here is a solution that throws away staged changes:

git reset file/to/overwrite
git checkout file/to/overwrite
Aftershock
  • 5,205
  • 4
  • 51
  • 64
  • 12
    Annoyingly, if the perceived difference comes from the fact that the file had its newlines changed when it was checked out, this will not fix the problem. – DanielSank Dec 18 '14 at 02:19
  • this is the best answer, imo, because it does not disrupt any staged items, but addresses the problem of the file preventing the pull – theRiley Feb 28 '18 at 17:25
  • 3
    @Timo I do not remember, it was seven years ago. – DanielSank Jan 29 '21 at 21:57
81

You can either commit your changes before you do the merge, or you stash them:

  1. git stash save
  2. git merge origin/master
  3. git stash pop
Eugen Konkov
  • 22,193
  • 17
  • 108
  • 158
Suneel Kumar
  • 5,621
  • 3
  • 31
  • 44
  • 13
    Point is, you shouldn't have to do this. Just take the current HEAD material and ..... merge it in! It's really simple, Git, all other VCS's do it... but nope. Linus had to make it annoying to use. – Jon Feb 08 '16 at 20:56
  • @Jon This solution is for Ubuntu, I have not found anything better then this. – Suneel Kumar Sep 19 '16 at 06:54
  • Unfortunately `--autostash` option is available only with `--rebase` option ( – Eugen Konkov Jun 22 '18 at 08:17
  • thats going to introduce so many problems its not worth it. Takes 5 mins at least to load also. Also introduces "Unlink of file" errors. downvote – Philip Rego Jul 09 '19 at 20:25
  • 1
    Is save option similar to git stash without save? git stash pop means take the last stash from the stack, so apply it to the index. – Timo Feb 02 '21 at 19:57
61

If you want to discard your local changes on one file you can do the following:

git checkout -- <file>

Then you could overwrite the file[s] with the latest version just doing:

git pull
pabloasc
  • 763
  • 5
  • 11
52
git pull --rebase --autostash
  -r, --rebase[=false|true|merges|preserve|interactive]
      When true, rebase the current branch on top of the 
      upstream branch after fetching. If there is a 
      remote-tracking branch corresponding to the upstream
  --autostash, --no-autostash
      Before starting rebase, stash local modifications away if
      needed, and apply the stash entry when done

I do not know why this is not answered yet, but solution, as you can see is simple. All answers here suggest same: to delete/save your local changes and apply upstream, then (if you save) apply your local changes on top.

What git pull --rebase --autostash does step-by-step:

1. your local changes saved by `--autostash`
2. your local commits saved by `--rebase`
3. commits from upstream applied to your branch
4. your local commits are restored on top of upstream
5. your local changes are restored to working directory

My case (probably yours too):

I have local changes (changes at working directory):

enter image description here

When I try to pull remote changes I get error:

enter image description here

This changes do not intersect with local changes:

enter image description here

So when I pull --rebase --autostash local changes saved and applied without any problem automatically

enter image description here

Now my local changes are little lower: enter image description here

Eugen Konkov
  • 22,193
  • 17
  • 108
  • 158
  • Nicely done! Can you take out the "TLDR" you have at the top? Perhaps "This is a better answer - PLEASE read." – learning2learn Feb 20 '21 at 13:21
  • @learning2learn: May you please describe why you dislike TLDR? – Eugen Konkov Feb 20 '21 at 14:20
  • 1
    Because I think it's worth reading and to me "TL;DR" (too long; didn't read), implies it's too verbose and perhaps not worth reading. But for me of all the different answers on this question, it most closely reflected my issue at the moment, and did exactly what I was looking for. (I'd used stash before, but somehow didn't know of autostash cli option). I think your answer should get more upvotes. – learning2learn Feb 21 '21 at 05:13
  • error: Pulling is not possible because you have unmerged files. hint: Fix them up in the work tree, and then use 'git add/rm ' hint: as appropriate to mark resolution and make a commit. – Fernando Torres Nov 03 '21 at 00:56
  • 1
    This answer is unique and very important – Saad Jan 09 '22 at 19:19
  • So with "your local commits are restored on top of upstream", do you mean they get properly auto-merged with the incoming data? (regardless of conflicts; I can obviously handle those locally) – Nyerguds Apr 07 '23 at 11:47
28

If your repository contains a few files which are removed from master:

  1. git checkout master
  2. git fetch origin
  3. git reset --hard origin/master
  4. git checkout -b newbranch
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nikhil K R
  • 677
  • 1
  • 9
  • 19
  • git reset --hard origin/master is the only thing that worked, out of all these solutions. Thank you. – Riley Hemphill Jan 11 '21 at 22:25
  • Thank you very much! I've tried all the answers above but none of them worked. I haven't changed anything and still got this error for file A, and when I tried stash, I got this error with 10 other files. Repeating endlessly... `git reset --hard origin/` did help! – Lenka Čížková Jun 06 '21 at 22:43
  • This was the only one that worked for me. Thank you! `git checkout -b newbranch` is out of scope. Question was to pull, so it would be `git pull`. – lcompare Feb 18 '22 at 14:02
21

Sometimes, none of these work. Annoyingly, due to the LF thing I think, what will work is deleting the files, then pulling. Not that I recommend this solution, but if the file doesn't exist, git won't uselessly inform you that your changes (which may not even be changes) will get overridden, and will let you continue.

Use at your own risk.

Jeremy Holovacs
  • 22,480
  • 33
  • 117
  • 254
  • 2
    When your stuck due to line endings, this method is a life saver – Dan Pisarski Mar 13 '18 at 18:51
  • This isn't working for me. The files don't exist locally and I am still getting the error. – PRMan Apr 07 '20 at 17:22
  • this even worked for a git merge master, when none of the other suggestions did – andrew lorien Mar 05 '21 at 03:48
  • What happened in me is that, I deleted the file on my local repo, and when I pull, the "about my local changes would be overwritten by merge" came up. – Clint Angelo 'Tec' Mercado Feb 01 '22 at 02:36
  • True for me too. Tried git checkout HEAD^ and git checkout HEAD -- and git checkout --. I'm working on my own files and never touched the files with conflicts. I didn't want to stash and then overwrite everything, just the conflicts...so I ended up deleting the file(s) and repulling. – cbishop May 20 '22 at 20:50
  • For me this worked as the only solution. Git told me I had to commit my ../environment.ts file, however I did not have any changes there and also could not use git stash. I deleted the file and was able to git pull again. I got the exact same environment.ts file from the origin. – MikhailRatner Feb 16 '23 at 13:53
21

Try this

git fetch --all 

git reset --hard origin/master

git pull origin master

It's work for me to force pull

Kasyful Anwar
  • 355
  • 2
  • 3
15

git stash save --keep-index did not worked for me.

below command worked as expected.

git reset --hard
git pull

It override all local changes if you don't need them.

Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
12

In the recent Git, you can add -r/--rebase on pull command to rebase your current branch on top of the upstream branch after fetching. The warning should disappear, but there is a risk that you'll get some conflicts which you'll need to solve.


Alternatively you can checkout different branch with force, then go back to master again, e.g.:

git checkout origin/master -f
git checkout master -f

Then pull it again as usual:

git pull origin master

Using this method can save you time from stashing (git stash) and potential permission issues, reseting files (git reset HEAD --hard), removing files (git clean -fd), etc. Also the above it's easier to remember.

kenorb
  • 155,785
  • 88
  • 678
  • 743
10

Here is my strategy to solve the problem.

Problem Statement

We need to make changes in more than 10 files. We tried PULL (git pull origin master), but Git shouted:

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

We tried to execute commit and then pull, but they didn't work either.

Solution

We were in the dirty stage actually, because the files were in the "Staging Area" a.k.a "Index Area" and some were in the "Head Area" a.k.a "local Git directory". And we wanted to pull the changes from the server.

Check this link for information about different stages of Git in a clear manner: GIT Stages

We followed the following steps

  • git stash (this made our working directory clean. Your changes are stored on the stack by Git).
  • git pull origin master (Pull the changes from the server)
  • git stash apply (Applied all the changes from stack)
  • git commit -m 'message' (Committed the changes)
  • git push origin master (Pushed the changes to the server)
  • git stash drop (Drop the stack)

Let's understand when and why you need stashing

If you are in the dirty state, means you are making changes in your files and then you are compelled, due to any reason, to pull or switch to another branch for some very urgent work, so at this point you can't pull or switch until you commit your change. The stash command is here as a helping hand.

From the book ProGIT, 2nd Edition:

Often, when you’ve been working on part of your project, things are in a messy state and you want to switch branches for a bit to work on something else. The problem is, you don’t want to do a commit of half-done work just so you can get back to this point later. The answer to this issue is the git stash command. Stashing takes the dirty state of your working directory – that is, your modified tracked files and staged changes – and saves it on a stack of unfinished changes that you can reapply at any time.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
STK
  • 167
  • 1
  • 7
10

git reset --hard && git clean -df

Caution: This will reset and delete any untracked files.

Yamen Ashraf
  • 2,637
  • 2
  • 20
  • 26
9

This problem is because you have made changes locally to file/s and the same file/s exists with changes in the Git repository, so before pull/push you will need stash local changes:

To overwrite local changes of a single file:

git reset file/to/overwrite
git checkout file/to/overwrite

To overwrite all the local changes (changes in all files):

git stash
git pull
git stash pop

Also this problem may be because of you are on a branch which is not merged with the master branch.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
BSB
  • 2,270
  • 17
  • 26
7

This worked for me to discard changes on the live remote server and pull from the source control GitHub:

git reset --hard
git pull origin master
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Gajen Sunthara
  • 4,470
  • 37
  • 23
6

You can use this for overwrite file

git checkout file_to_overwrite
Deepika Patel
  • 2,581
  • 2
  • 19
  • 13
6

The best way to solve this problem is:

git checkout -- <path/file_name>

After that you can overwrite the file by:

git pull origin master
Forhadul Islam
  • 1,159
  • 11
  • 13
  • I had the problem mentioned because I'd updated the index to assume the files were unchanged. It still wouldn't let me do the pull. I used `git checkout -- path/*` just once, and it allowed me to execute the pull after. – Stephen O'Flynn Oct 11 '17 at 13:32
6

If you want to keep production changes on the server, just merge into a new configuration item. The processing method is as follows:

git stash
git pull
git stash pop

Maybe you don't execute all operations. You can know what you can do next.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
YanQing
  • 61
  • 1
  • 3
4

If you want to overwrite specific changes, you need some way of telling it which ones you want to forget.

You could try selectively stashing the changes you want to abandon using git stash --patch and then dropping that stash with git stash drop. You can then pull in the remote changes and merge them as normal.

Will Vousden
  • 32,488
  • 9
  • 84
  • 95
4

The simplest solution is:

git reset --hard && git pull
Jackkobec
  • 5,889
  • 34
  • 34
4

Error "Your local changes to the following files would be overwritten by merge" comes because you have some changes in the local repo that have NOT been commited yet, so before pulling from remote repo just commit the changes in local repo.

Lets say your remote repo has some branch xyz and you want that remote repo xyz branch to be merged into (copied to) local repo xyz branch then,

{
git checkout xyz                  //check out to the respective branch in local repo
git commit -m "commiting message" //commit changes if any, in local repo branch xyz
git pull                          //it pulls remote xyz branch into local xyz branch
}
ASR
  • 311
  • 2
  • 14
4

Due to your branch is behind 'origin/dev' by xx commits, and can be fast-forwarded. Try this command:

git checkout .
git pullenter code here

Hope that fix your issue.

NikeCon
  • 77
  • 2
  • This sounds most like what the original question is asking for, i.e. the quickest way to just discard the local changes and accept what's at origin. Possibly combined with the other suggestion of `git clean -f` to clear untracked files. – John Dec 21 '22 at 15:58
3

I had a special case of this: I had a file with --assume-unchanged on it. It was hard to locate, as the git status command was not showing any changes

  • I have this same problem. Did you find a way to get around it? I suppose I could remove and then re-add assume-unchanged... what I did was just checkout those files manually to get unchanged versions... just wondering if there is a way to just make the checkout / rebase / merge just overwrite them. – David Oct 11 '16 at 22:20
  • 1
    No, I had to abandon the whole "assume unchanged " thing. –  Oct 13 '16 at 12:57
3

I was ignoring a file in my repo and when I did git pull upstream master I got the following error:

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

To resolve it I did the following

git update-index --no-assume-unchanged myfile.js

I then did git status and got this message

On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)

        modified:   myfile.js ** 
        ^^^^ THIS IS KEY ^^^^^ - FILE SHOULD APPEAR MODIFIED!!

no changes added to commit (use "git add" and/or "git commit -a")

Then I did git checkout myfile.js followed by git pull upstream master. This time the git pull operation was successful.

Devin Rhode
  • 23,026
  • 8
  • 58
  • 72
Dmitry
  • 4,143
  • 10
  • 46
  • 57
  • I recommend dealing with individual files. What I do in this case is first `git diff foobar.js` and then once confirmed nothing precious will be lost: `git restore foobar.js` – jakebugz617 Dec 15 '21 at 21:07
  • This was the most helpful to me, I had previously "silently ignored" a change with `git update-index --skip-worktree dockerfile`, and was able to restore it with `git update-index --no-skip-worktree dockerfile` – Devin Rhode Jun 14 '23 at 19:53
3

Example

[root@localhost www]# git pull
Username for 'http://159.65.151.11': amol
Password for 'http://amol@159.65.151.11':
remote: Counting objects: 34, done.
remote: Compressing objects: 100% (34/34), done.
remote: Total 34 (delta 13), reused 0 (delta 0)
Unpacking objects: 100% (34/34), done.
From http://159.65.151.11/OpenCC
   f793c8e..b8fe60c  v1.18.0_24Feb2022 -> origin/_v1.18.0_24Feb2022
error: Your local changes to the following files would be overwritten by merge:
        cc/routes/web.php
Please, commit your changes or stash them before you can merge.
Aborting

Solution(ignore already commit change in local file)

git checkout HEAD^ cc/routes/web.php
git pull
Amol
  • 55
  • 4
2

If this error is because of line endings,

git add
git checkout mybranch

will work. I'm not really sure why it works.

flaviut
  • 2,007
  • 3
  • 23
  • 32
2

I encountered this when pulling from the master.

The way I handled it, using Visual Studio;

  1. First, I performed Undo commit on my solution.
  2. Then I did the Git pull process.

Hope this helps!

AJ Macapaz
  • 21
  • 2
2

Before pulling, you have to commit all files that are not committed yet, then you will not receive that message from AS.

TaQuangTu
  • 2,155
  • 2
  • 16
  • 30
2

I'm new in git and not sure if my solution is a good idea.

I've tested ALL of answers and none of them worked for me!

But I found another solution:

1. Backup both of local and repository versions of the file.
2. Delete the file from repository.
3. git add .
4. git commit
5. git push

Hope this helps.

Milad Safaei
  • 492
  • 1
  • 5
  • 16
1

My solution was delete the files from outside the IDE that are going to be overwritten, then pull.

(you can always backup and manually merge untracked data)

Ali Kleit
  • 3,069
  • 2
  • 23
  • 39
  • 1
    I do the same. This is the simplest. Execute **rm** to remove the target file or **mv** to backup the target file to a new filename, then execute **git pull**. – oraclesoon Sep 22 '20 at 04:11
  • i do the same but it seems wierd to me that this common issue does not have a designated command – itay_alon May 13 '21 at 10:50
0

For Pycharm, you can do Git-->Revert and then pull.

Munichong
  • 3,861
  • 14
  • 48
  • 69
0

This message can also happen if git-lfs is used and a file pointer was overwritten by a real file.

then you use:

git stash
git lfs migrate import
git pull

full output from my case

λ git stash
Saved working directory and index state WIP on master: 5d4ad47 Merge branch 'feature/...' into 'master'
Encountered 1 file(s) that should have been pointers, but weren't:
        public/apple-touch-icon.png

λ git pull
Updating 5a4ad44..b25f79d
error: Your local changes to the following files would be overwritten by merge:
        public/apple-touch-icon.png
Please commit your changes or stash them before you merge.
Aborting

λ git lfs migrate import
migrate: Fetching remote refs: ..., done
migrate: Sorting commits: ..., done
migrate: Rewriting commits: 100% (0/0), done
migrate: Updating refs: ..., done
migrate: checkout: ..., done


λ git pull
Updating 5d4ad47..a25c79a
Fast-forward
 public/apple-touch-icon.png | Bin 2092 -> 130 bytes
 public/favicon.ico          | Bin 6518 -> 1150 bytes
 2 files changed, 0 insertions(+), 0 deletions(-)

see https://github.com/git-lfs/git-lfs/issues/2839

c33s
  • 2,612
  • 1
  • 30
  • 43
0

Check the file which you are okay to overwrite and lose local changes and then

git checkout --ours ${filePath}
git merge upstream/master
Divyesh Kalbhor
  • 385
  • 3
  • 19
0

In my case, I had configured a few months before not to track the file locally with

git update-index --skip-worktree <absolute path to file>

and that file changed in remote repo and confused git so i used

git stash
git update-index --no-skip-worktree <absolute path to file>
git pull origin master
git stash pop

and it worked

-1

For me this worked:-

  1. First I cleaned all the untracked files, run-> git clean -f.
  2. git pull
Amar Kumar
  • 2,392
  • 2
  • 25
  • 33
  • 4
    For beginners, it should be added that "clean" means removal of files... If you don't want to delete the untracked files, do not do this – Agile Bean Oct 23 '21 at 11:44
-3

Simply commit the local changes and merge commit -a

UltraSibz
  • 15
  • 1
  • 2
  • The original question states changes should be overwritten, not committed. If this is the answer you want you need to include instructions for getting rid of the bogus commit. – sf_jeff Nov 13 '20 at 04:34
-4

If you want to push all files, then try this git push --force-with-lease origin master