Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git pull - merge remote changes before pushing again

Tags:

git

github

I have recently changed my programming machine, which is leading to some startup issues in getting my new coding source to integrate seamlessly with my existing Github repo and my app on Heroku.

I originally used git clone to clone the Github repo onto my new machine. Since then, something has happened.

  • When I do git add ., git commit -m "mychanges", and git push, the code gets sent straight to Heroku. It used to get sent to my own Github repo, but I understand that's a simple matter of redefining what is considered 'origin'.
  • After redefining origin to my Github repo's address, and typing git push origin master, I get the following error:
    error: failed to push some refs to '[email protected]:...'
    To prevent you from losinghistory, non-fast-forward updates were rejected. Merge the remote changes ('git pull') before pushing again.

I am concerned that my last two days of coding will be lost if I do a git pull (I have backed everything up just in case).

My current idea: do the git pull and manually update the last two days' files from my backup, then finally do my git push. Is this the right way to go, or is there a more elegant solution?

like image 980
sscirrus Avatar asked Dec 22 '22 20:12

sscirrus


1 Answers

git will not overwrite your data unless you use reset. git pull will take the commits on origin/master (assuming your branch is master) and try to fast-forward your local branch to that point, merging any local changes. If you've committed locally, and those commits are meant to go after any more recent commits on the server, you can do git pull --rebase instead.

like image 184
Zeppomedio Avatar answered Jan 07 '23 04:01

Zeppomedio