Reputation: 672
I'm aware of the git config:
git config branch.master.pushRemote no_push
Which has saved me a number of time from accidentally pushing to master remote branch, but a couple of times this hasn't worked, and I couldn't understand why, until today, I realised that if I push but set upstream... Well it pushes to the origin, which isn't great.
git push --set-upstream origin {git_current_branch}
<-- I have this as alias gpsup
hence it's an easy mistake to make.
How can I disable pushing to the remote branch even if I accidentally use the --set-upstream flag?
Upvotes: 0
Views: 1178
Reputation: 1324168
How can I disable pushing toe the remote branch even if I accidentally use the
--set-upstream
flag?
You need to configure the remote side.
On GitHub, as commented, that would be using a branch protection rule.
But other remote Git repository hosting services (Bitbucket, GitLab, ...) have their own version of that too.
The point is: a git config solution is local to your workstation, and (as you have seen) might not be 100% reliable.
A remote-side solution is easier to setup and to enforce (not just from your workstation, but for everyone, from anywhere).
Upvotes: 2