In this movie we are going to talk about what happens when you try to push to a remote server
that has been updated.
Here is the situation that I'm talking about.
Imagine that we have our remote server and our local repository and both of them have
three commits in it.
We do a fetch, so we know that we are completely in sync, we just have these three git commits.
So once I know that I am in sync, I start my work for the day.
And over the course of the next hour I put together a commit.
I then commit it to my local repository.
At the same time though, my coworkers and collaborators have also been making commits
and they've been pushing their commits up to the remote server.
So now when I try to push my commits to the remote server, the remote server says, well,
I don't know what to do with your commits, there has been some new stuff that's come
in in the meantime.
Git never tries to do a merge during a push.
Instead what Git says is, some new stuff has come in. I'm not sure what to do about all
this. You need to fetch the changes that are on the remote server, then sort it out on
your end and come back and try again.
So we do a fetch.
We've got the new information about what's on the remote server, we now see why there's
a problem, oh, there were some other commits there.
But that doesn't solve our problem. We've still got to merge our changes in with those.
This is not just because there's a conflict, it's not because I changed Line 37 of index.html
and someone else changed Line 37 of index.html, it's just simply because there were new commits.
So what we need to do in this case is git merge origin/master, that will then merge
my changes in with origin/master and create a new merge commit, and then I can push again
and the remote server will accept it.
If there were merge conflicts, I would need to fix those just like we do with the normal merge conflicts.
But in most cases you don't even get conflicts, you just simply have to do the merge in order
to send it to the remote server.
So just keep that in mind, if you can't push the remote server, you'll just need to fetch,
then merge, then push again.
That way we can make sure that everyone's changes are taken into account.