2

Consider a remote branch that requires a pull request before changes can be pushed to it. Assume a team member pushes to this remote branch anyway. Under what circumstances does the team member see a message saying that the push was rejected (because the remote branch is protected), and under what circumstances does the team member gets no rejection during the push?

Note. I understand that in the latter case, the user will see a Compare & pull request button in their GitHub profile. So the fact that their push does not get rejected does not mean that the remote is updated with the local changes.

torek
  • 448,244
  • 59
  • 642
  • 775
H D
  • 151
  • 6
  • It's up to GitHub to deliver the reason. Git will then display the reason to stderr; it's up to whatever is *running* Git to display the stderr output to the user. As far as GitHub themselves go, I believe they always deliver the reason, but I could easily be wrong about this (I only have limited experience with GitHub's protected branches). – torek Jun 25 '22 at 11:43
  • @torek Thank you for the edit and the comment! :) – H D Jun 25 '22 at 13:17

1 Answers1

0

under what circumstances does the team member gets no rejection during the push?

From protected branches, you would need to allow specific people the permission can push to the protected branch.

Also, by default, protected branch rules do not apply to people with admin permissions to a repository.

So the fact that their push does not get rejected does not mean that the remote is updated with the local changes.

Something on the remote should be updated anyway: the user feature branch (candidate to be a PR branch, and not protected against push) should be updated.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you very much! Is it correct to say that in the latter case, the `push` command from the local will act identically to a `fetch` command from the remote? It seems to me like both do the following: (i) transfer all local commits to the remote, (ii) leave refs in the remote completely untouched. – H D Jun 25 '22 at 13:14
  • @HD Yes, except when we are talking about github.com as a remote, GitHub never fetches. A user always pushes. – VonC Jun 25 '22 at 13:18
  • I have another question if you do not mind. Can we implement the above exact scenario, i.e., _transfer all local commits to the remote *but* leave the remote's refs completely untouched_ even when the remote is not protected? The following post suggests it is impossible to do this if the local and remote branches have the same name. Can you kindly share your opinion? https://stackoverflow.com/questions/65108889/git-push-commits-without-updating-remote-branch-ref – H D Jun 25 '22 at 13:33
  • 1
    @HD You could push them to a [*fork* of the remote](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/about-forks), in order to leave the original remote untouched. Later on, through pull request, you can merge back those contributions back to the original remote. – VonC Jun 25 '22 at 13:34