1

I tried pushing some changes I made to my teams repo but received the following error:

$ git add .
$ git commit -m "message"
$ git push origin master
! [rejected]  master -> master (fetch first)

I then tried doing a fetch (as instructed by the git hint) and received:

$ git fetch
$ git push origin master
! [rejected]  master -> master (non-fast-forward)

Now I am being instructed to git pull but am afraid my local changes will be overwritten.

After some googling I read that I should do a git stash first to protect my local changes but am now receiving:

$ git stash
No local changes to save

So my question is what should I do next to successfully do a push while not overwriting any of my local changes in the process?

Thanks!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Espresso
  • 740
  • 13
  • 32
  • Now I am thinking I should do a `git merge`. Will that overwrite my local changes? – Espresso Nov 08 '19 at 18:52
  • 2
    `git pull` will not override your local settings. A `git pull` is actually a `git fetch` and a `git merge`. You probably want to stash your changes then pull. – EncryptedWatermelon Nov 08 '19 at 18:56
  • 1
    Ok, so a `git pull` followed by a `git push` was all that was needed. I duplicated all of my local changes as a backup but @EncryptedWatermelon was correct. A `git pull` will not override any local changes. Thanks all :) – Espresso Nov 08 '19 at 19:10
  • 1
    You should never need to duplicate your files if they have been stashed or committed. Commit early and often. – evolutionxbox Nov 08 '19 at 21:32

1 Answers1

1

Just do git fetch first it will only get the changes in your origin/branch(you can see them when you do git branch -a) remove the conflicts after merging and then push them to your origin

Ashish Rawat
  • 90
  • 1
  • 8