2

How can I push the local repo changes to remote repo and remote has already updated files which I don't have? We are working in a team so continuously there are changes that need to be pulled first but unfortunately, my code gets disappeared when I pull it.

I am using the following commands: In order to PUSH

git add .
git commit -m 'msg'
git push -u origin development
! [rejected]        development -> development (fetch first)

error: failed to push some refs to 'https://github.com/gsesltd/metis_maza.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

In order to PULL:

git pull origin development

My files get updated and all my written code is gone now. Thanks to git reset that I have my code.

Can somebody please tell me how can I push the code without force push + I want to have all the remote updates too? How can I do that?

torek
  • 448,244
  • 59
  • 642
  • 775

1 Answers1

0

In order to minimize any "code disappearance" on pull, do a rebase instead: that would replay your own local commits on top of fetched commits from the remote repository.

Since Git 2.6 (Q3 2015), type:

git config --global pull.rebase true
git config --global rebase.autoStash true

Then a simple git pull will at least put your commits on top.

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