Configure Git to show a warning when pushing to a different branch than the current branch

Is there a way to configure Git / Github to request a warning message for this scenario:

$> git branch
$> *my_special_branch
$> git commit -am "I am about to make a grave error"
$> git push origin master

      

Basically I want to prevent me and my team from going to a different remote branch than the current one I'm on, without a prompt or confirmation ...

so basically I want to prevent pushing to the remote master branch from any branch, but the local master branch ...

+3


source to share


3 answers


I think the best way to do it is like this:

Default behavior of "git push" without specifying a branch

you can set git to default behavior

for example, if you set up Git like this:

git config --global push.default current

      



you can omit branchname and by default it will push the current local branch to the remote branch with the same name.

so if you run this command omitting "refspec" / branchname

$> git push origin

      

then it will only push the current branch to the remote / seed-level branch with the same name

this saves you the trouble of typing long branch names and serves as a security bit

0


source


I don't think there is a way to do what you are asking Git to do. Since you and your team members are pushing access to the repository, you can push to any other branch you want, own, or otherwise.

The good thing you can do is commit something to master when you are on another branch, and that way you can't accidentally push because the master is in front with a commit.



Another thing is to just push yourself for yourself and then your team members will have to make a pull request if they want to commit to something, but that's not perfect I'm sure.

Interesting question though, I'll save it for later in case someone comes up with a specific answer. Sorry, but couldn't help.

+2


source


As per my understanding, you want custom permissions for specific branches.

There are various tools (repository management tools) that provide this functionality.

with tools you can provide to users at the branch level. Because the master branch is always ready to be deployed, so only the master will have access and no one else can merge into the master branch. Likewise, developers will have access to create a pull request (to review the code and request to merge with another branch) and management will review it and once the leader is satisfied with the functionality they approve and merge the code with the master branch.

Choosing a repository management tool requires if the repository is in place or in the cloud. if i suppose my recommendation is to use Stash else you can go with the bit bucket or github for the cloud.

+1


source







All Articles