Reputation: 2235
git status
It will get:
On branch master
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
nothing to commit, working tree clean
Then if I run
git fetch -a && git merge origin master
It will get:
Already up-to-date.
I wonder why can't I get a merge operation?
Upvotes: 2
Views: 2741
Reputation: 83527
When you do git merge origin master
, both origin
and master
are interpreted as branch names. However origin
refers to another repository (called a remote), not a branch. You can perform this action with a simple change:
git fetch && git merge origin/master
Here origin/master
refers to a remote tracking branch. This is a local copy of the branch which was fetched from the origin
remote. Alternatively you can just do
git pull origin master
Or since you already are on the master
branch, you can do
git pull
Upvotes: 3
Reputation: 3987
git fetch && git merge origin/master
is different from
git fetch && git merge origin master # Invalid
because git fetch
updates .git/refs/remote/<remote server name>/<remote branch name>
. And unless specified, you're always referring to your HEAD
of the working directory, which is in .git/refs/heads/<branch name>
Note: git merge
is a local operation. git merge origin master
is an invalid operation. As discussed here SO question
Git fetch
git fetch
fetches information on remote branches, but does not make any changes to your local master
branch. Because of this, master
and origin/master
are still diverged. You'd have to merge them by using git pull
When you make a commit, your local master branch is ahead of origin/master
until you push those changes. This case is the opposite, where the origin/master
branch is ahead of your local master branch. This is why you are getting different outcomes
Upvotes: 4