0

My origin master and local master have diverged as below. I want to ignore the changes in origin/master and be able to push my local changes to origin master. I did git pull followed by git stash and tried to push but that did not help. I don't want to create a new commit and merge changes from origin master onto my local master.

[~/Documents/projectRepo]$ git status                                                                                                                                                    *[master]
On branch master
Your branch and 'origin/master' have diverged,
and have 40 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
    deleted by us:   file1.json
    deleted by us:   file2.json

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

when I do force push without doing pull, I get this:

git push -f origin master                                                                                                                                                                       
Total 0 (delta 0), reused 0 (delta 0)
remote: error: GH003: Sorry, force-pushing to master is not allowed.
To ssh://github.com/zack/projectRepo.git
 ! [remote rejected]         master -> master (pre-receive hook declined)
error: failed to push some refs to 'ssh://github.com/zack/projectRepo.git'
Zack
  • 2,078
  • 10
  • 33
  • 58
  • 2
    You are currently in the middle of an incomplete merge. You *must* either complete or abort the merge before you can do anything else (at least in this work-tree). – torek Jun 29 '20 at 18:23
  • It sounds like you wanted to force push your changes to blow away the other changes in origin/master. But instead you did a pull which attempts to merge those changes in first. First abort the merge, then make sure your branch is how you want it to be, then force push it replace origin/master with your version of master. – TTT Jun 29 '20 at 18:30
  • I updated the question with details about force push. It fails as I am not allowed to do force-pushing to master – Zack Jul 01 '20 at 18:19

1 Answers1

-1
  1. You will have to abort the merge first. git merge --abort.
  2. Pull all the changes from origin/master. git pull
  3. Then do git merge origin/master
  4. Then use your IDE to resolve the conflicts(easier with Visual Studio code). Choose "Accept the Current changes". You'll have the options to (a)"Accept the Incoming changes"(your local will be overridden by master changes) or (b)"Accept the Current changes"(you choose to keep you local changes) or (c)"Accept both changes"(you choose to accept the changes from master and also keep your local changes) .
  5. Add your files using git add <your_file_name>
  6. Commit. git commit -m "Resolving conflicts"
  7. Push. git push
Sven Eberth
  • 3,057
  • 12
  • 24
  • 29