Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: Why "Merge branch 'master' of ... "? when pull and push

I'm still git newbie. I modified some source files and committed. Then, I did git push. But, I got this error.

To /foo/bar/  ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to '/foo/bar/' To prevent you from
losing history, non-fast-forward updates were rejected Merge the
remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

This reject seems that I didn't git pull before push. So, I did git pull. Okay, there were two modified files by others.

Then, I was able to git push successfully.

Question: In this case, I'm seeing one more log like following with my original commit message:

commit 59e04ce13b8afa...
Merge: 64240ba 76008a5
Author: Jone Doe <[email protected]>
Date:   Fri Mar 15 11:08:55 2013 -0700

    Merge branch 'master' of /foo/bar/

And this is my original commit message.

commit 64240bafb07705c...
Author: Jone Doe <[email protected]>
Date:   Fri Mar 15 11:06:18 2013 -0700

    Fixed bugs and updated!

I'd like to understand why "merge branch master of location" is added.

like image 657
Nullptr Avatar asked Mar 15 '13 18:03

Nullptr


People also ask

Why does git merge when I pull?

git pull causes merge commits because git is merging. This can be changed by setting your branches to use rebase instead of merge. Using rebase instead of merge on a pull provides a more linear history to the shared repository. On the other hand, merge commits show the parallel development efforts on the branch.

Does merging master into branch change master?

git merge master will update your current branch with the changes from your local master branch, the state of which will be that of when you last pulled while on that branch.

Do we need to merge after pull?

In a pull request, you propose that changes you've made on a head branch should be merged into a base branch. By default, any pull request can be merged at any time, unless the head branch is in conflict with the base branch.

Does git push merge to master?

All git does in the master branch is to move the HEAD pointer in the master branch to the latest commit from the “dev” branch. Once the merge is done, make sure to do a git push, to push your changes to the remote repository.


2 Answers

When you did a git-pull, modifications from the remote branch were merged into your local branch. The automatically generated commit signifies that.

Merging could have resulted in conflicts, which would then need to be resolved manually. In your particular case, this did not happen and git could take care of everything.

like image 186
r.v Avatar answered Oct 19 '22 08:10

r.v


If there could be changes by others, it might be a good idea to do a git pull --rebase (i.e., add your new changes after the remote changes; this might find conflicts you'd have to resolve) and then git push the result. Be careful, this creates new commits that did never exist before (as does any history rewriting), but it gives a clean, linear history (no tangle of merges)

like image 13
vonbrand Avatar answered Oct 19 '22 08:10

vonbrand