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.
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.
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.
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.
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With