1

When I develop on a branch at some point before the Pull Request I do:

$> git checkout myBranch
$> git pull
$> git rebase origin/master
# fix conflicts and --continue
$> git push --force 
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Counting objects: 21, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (11/11), done.
Writing objects: 100% (11/11), 1.59 KiB | 0 bytes/s, done.
Total 11 (delta 8), reused 0 (delta 0)
To [email protected]:bar/foo.git
+ 64f1387...ed6f9be myBranch -> myBranch (forced update)
+ ccaadf5...42e0c8d master -> master (forced update)

The problem here is the last line, a force push to master. This shouldn't have happend, I only wanted to force push to myBranch. But thats not all, the force push to master results in a master branch which now misses the last couple of commits. Which, I think, is weird, because I just did a pull. Can someone explain to me what just happend ? I think the cure is to do

$> git config --global push.default simple

and/or

$> git push --force origin/myBranch

1 Answer 1

3

About pushing all the branches, you are right, that is because of push.default=matching. From the docs of push.default:

matching - push all branches having the same name on both ends...

That may be surprising, and that's why the default is changing to simple.

About the master going back, that's what happens when you use --force... you have to be very careful.

The problem is that you did git pull, that is equivalent to git fetch and git merge. The fetch synchronized all the origin/* branches, and the merge advanced your myBranch to origin/myBranch. But as it happened, master was not updated to origin/master (as it was not the current branch when doing the merge). So when you force-pushed, you rolled back origin/master!

The morale of the story is:

When using --force, never trust the defaults!

That's valid for many commands, not just git.

Sign up to request clarification or add additional context in comments.

2 Comments

thnx a lot! Whats new for me is that when you are in myBranch and do a git fetch, go back to master that you still have to do a git pull before getting the newest commits on master! I guess this has to do with the position of HEAD, so it actually makes sense!
@JeanlucaScaljeri: And that's why I never do git pull. I do git fetch frequently (as it does not touch the local branches), and then git merge/rebase when needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.