It's likely that someone else (e.g. your colleague) has put commits onto origin/master
that aren't in your local master
branch, and you are trying to push some commits from your local branch to the server. In 99% of cases, assuming you don't want to erase their work from origin
, you have two options:
2) Merge their changes into your local branch, and then push the merged result.
git checkout master
git pull # resolve conflicts here
git push
(Note that git pull
is essentially just a git fetch
and a git merge
in this case.)
1) Rebase your local branch, so that it looks like your colleague made their commits first, and then you made your commits. This keeps the commit history nice and linear - and avoids a "merge commit". However, if you have conflicts with your colleague's changes, you may have to resolve those conflicts for each of your commits (rather than just once) in the worst case. Essentially this is nicer for everyone else but more effort for you.
git pull --rebase # resolve conflicts here
git push
(Note that git pull --rebase
is essentially a git fetch
and a git rebase origin/master
.)