1

I have two computers at home, one with Windows and one with Linux and I have one big repository called Work that I put on Git. But I work with this remote from both computers. I have created the repository initially on one and create the git repository (on bitbucket) from there. And I was able to make commit, push or pull. But I also make modifications from my second computer after I clone and git init the Work repository (but I do not make modifications on the same files), and when I tried to push it makes an error

error: failed to push some refs to '...'
hint: Updates were rejected because the tip of your current branch is behind

I think this is because I made modifications from the other computer but shouldn't it understand that the only modifications commited here should be merged with the current branch even if some other files have been modified in other subrepositories ?

I tried a pull but it doesn't work, and I tried a merge. Same. I am kind of lost for solutions. Can you help please ?

Stéphanie C
  • 799
  • 8
  • 29
  • 1
    You work with two computers in the same way two distinct persons would work. You treat each local repository on each computer separate from the other and exchange information by pushing and pulling (either directly, or as you are trying using a central repository). Unfortunately, the error you are giving is not really helpful. You should compare the `git log` of both repositories to see if they share a common history. If they don’t, you should do a fresh clone from the remote to sync them all. – poke May 04 '15 at 20:50
  • What do you mean by "doesn't work" in your last paragraph? – Matthieu Moy May 05 '15 at 06:33
  • It doesn't return any error, but still the problem persists. – Stéphanie C May 05 '15 at 09:39

2 Answers2

1

The error message is telling you that you need to update your local repository before it can successfully push anything to the remote server. The reason: the other machine has previously pushed to the remote server, which makes it the most recent update to the repository.

The scenario generally works as thus:

  • User A and User B are working on a single remote.
  • User A commits their work locally and pushes to remote successfully.
  • User B commits their work locally, but must then merge the work that User A has done (typically via git pull) before they have the ability to push.

While we await a more specific message about git pull not working, for now the advice I have is for you to perform git pull on the machine you're seeing this error from, then pushing (after you resolve any potential merge conflicts).

Makoto
  • 100,191
  • 27
  • 181
  • 221
0

I had this problem too.. The output surprised me:

git push github master
To git@github.com:Answer_Bot-project/project.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:Answer_Bot-project/project.git'

If I remember correctly, the general approach was to use a variation of the following commands:

git fetch github; git merge github/master

Perhaps take a look at this link for further information: Git non-fast-forward updates were rejected Merge the remote changes.

I hope it can help you!

Community
  • 1
  • 1
Answer_Bot
  • 35
  • 3