Tad Tad -3 years ago 171
Git Question

Git push -f on branch affecting master

Let's say I make a branch off master and make some commits to my branch, commit1, commit2. In the meantime, two other people merge two pull requests to master, hence my branch would be 2 commits behind. If I make some change and do git push -f on my branch, will this delete the last two pull requests from master?

Also, is it possible to see how did two commits get deleted from master using Github? Is there any logging/history kept for this purpose?
Thank you for any answers.

Answer Source

I beg to differ with @Humdinger from personal experience. As mentioned on What is the difference between git push.default=current and push.default=upstream?, push.default setting can change the behaviour of git push. For instance, if push.default=matching, git push causes all branches to be pushed, i.e., all branches having the same name in both ends are considered to be matching.

In your case, if you have push.default=matching and if your clone is two commits behind the master, you will be overwriting the master branch AS WELL AS the remote branch (assuming branch != master) even though you just wanted to push the changes on your branch. Having push.default=upstream should avoid this issue.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download