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.
Read https://stackoverflow.com/a/7104747/2961170 for more information.
Answer from fisk on Stack Overflowgit 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.
Read https://stackoverflow.com/a/7104747/2961170 for more information.
Using git merge origin/master refers to the master branch on the server. git merge master refers to your local master branch.
By using git pull you can merge them if they diverge.
what does git merge origin/master do? - Stack Overflow
github - Is git merge origin master same as git merge origin/master? - Stack Overflow
merge - merging (git) origin to my current local working branch - Stack Overflow
git merge origin master doesn't work - Stack Overflow
Not sure if this is the right place to ask this. My branch is behind origin master by many commits, I tried to git merge master to my branch earlier but my git log history now shows a bunch of other people’s commits, but I actually just wanted to keep my branch up-to-date with master in one commit only, something like “Merge branch ‘master’ into ‘some-branch’” any help is appreciated. Thanks
git merge origin/master can do one of two things (or error).
In the first case, it creates a new commit that has two parents: the current HEAD, and the commit pointed to by the ref origin/master (unless you're doing something funny, this is likely to be (the local pointer to) the branch named master on a remote named origin, though this is completely conventional).
In the second case, where there is no tree-level merge necessary, rather than creating a new commit, it updates the currently checked-out ref to point to the same commit as is pointed to by origin/master. (This is called a fast-forward merge -- git can be directed to either always or never do this when you merge through command-line flags).
It does not call git commit directly, which is a higher-level (porcelain in the git-parlance) command intended for users.
Calling git merge master/original will try and resolve master/original to a commit, which will almost certainly (again, unless you've done something deliberate) not be the same as origin/master. If you happen to have a remote named master that has a branch named original, it will create a new commit which has that as the second parent.
You may find git help rev-parse to be helpful in deciphering how git attempts to resolve ref names or other notations into commits.
What this does is merges the branch referred to as origin/master into your current branch. The order is very important. The word origin means the place from which you cloned your repository, i.e., the origin of the repository, the word master is just a branch name, however master is usually used as the main branch, or the trunk branch as some other systems call it.
Merge might need to do a commit depending on the state of your development. If your history hasn't diverged from the origin, it can do what is called a fast-forward---all that needs to be done is put the new history on top of yours. If your development has diverged from the origin then if the merge can be done with no conflicts then the merge is done and a new commit is recorded at HEAD to specify the merge and the two parents.
Furthermore, if merging can't be done because of a conflict, your working copy is updated to reflect the fact that there are conflicts, then when you fix them, you manually make the commit that records the merge.
It is not the same at all. git merge origin/master will merge your remote-tracking branch master to your current head. git merge origin master will attempt to create an octopus merge with branches origin and master to the current head. It will probably fail, because most likely you do not have a branch named origin (which would be very confusing, since it is the default name for a remote repository).
Use git merge origin/master.
Merging the latest from master as it is in origin right now is a 2-step process.
- Fetch
- Merge
This can be done in different ways. The step-by-step one is
git fetch origin
git merge origin/master
There are some things you can do to automate this process somewhat. One of them is to setup origin/master as the upstream branch of the local branch you are dealing with... something like git branch --set-upstream-to=origin/master).... then you can do
git pull
git pull takes care of running the fetch and then merging.
Another way, if you haven't set the upstream branch is to do
git pull origin master
Which does the same thing: fetch, merge.
newbranch should be current branch, to make sure you can checkout it, then you get updated from you repo using fetch and then merge newbranch with master
About checkout: branch, with which you're currently working is already checkout. To switch to another branch you need checkout it. If already you're working with branch you don't need checkout.
git checkout newbranch
git fetch
git merge origin/master
instead merge you can use rebase, in this case last line should be replaced
git rebase origin/master
Merge and rebase just update you branch with information from other branch. Merge get commits from master and add them to your branch. Rebase did the same by a little different way. See Merging vs. Rebasing. For now just forget about rebase, just do merge.
I think you should do:
git stash#store your changes of your local newbranch in a stackgit pull --rebase origin/master#take the origin latest change in local newbranchgit stash pop#pop the changes in step1 that is stored in stackif there is a conflict, you should resolve confict, and then continue to work until you push all of your changes in origin.
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
Source
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