git pull
is the combination of two commands: git fetch
, followed by git merge
or git rebase
(that second command depends on your configuration, and the options you pass to git pull
).
"conflicts" can only occur at the second step. If you don't know where the conflicts come from, you can return your local branch to its pre-merge state by simply cancelling the merge or rebase :
# run:
git merge --abort
# or:
git rebase --abort
# if in doubt, run one then the other
Once you have aborted the merge or rebase, you have restored your local branch, and still have the result of git fetch
: the remote branches have been updated.
Inspect the history you see in your local clone :
- in a terminal, you can run :
git log --oneline --graph mybranch origin/mybranch
# or:
# - @ is a shortcut for 'HEAD' or 'the current commit'
# - @{u} is a shortcut for 'HEAD@{upstream}' or 'the upstream branch of my active branch'
git log --oneline --graph @ @{u}
- or open a graphical viewer (
gitk
, gitg
, git-extensions
, git-kraken
, your IDE integrated viewer ...) and look at the combined histories of your current branch and its remote counterpart
You should have the opportunity to see what changed.
Once you have a better understanding of what happened, you can run
git merge origin/mybranch
git merge @{u}
# or
git rebase origin/mybranch
git rebase @{u}
to reapply the exact same action as the second step of git pull
, or do some changes on your branch first (drop a commit, cherry-pick another commit ...) before merging or rebasing.
If you want to avoid the "why do I get conflicts I wasn't aware of ?" situation, stop using git pull
, use git fetch
followed by git merge
or git rebase
. This gives you the opportunity to inspect what changes you received before dealing with them.