1

In our team we always do code reviews, through pull requests on feature branches. After a code review, we merge the feature branch to the develop branch (using the Merge button in the Bitbucket web interface).

Sometimes a developer accidentally commits and pushes directly on the develop branch (forgot to create a feature branch).

To avoid such accidents: How can I make the develop branch read only in IntelliJ?

1 Answers1

2

Even if you accomplish this in IntelliJ one still would be able to push from the command line client.

To protect a branch from direct pushes you want to configure a server-side hook. How to achieve this depends on your setup e.g. Github has a feature called protected branches. Few options are mentioned here.

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
  • Also BitBucket have an option for this. The option "Prevent changes without a pull request" can be found under branch permissions. You want to set this on server side (Github, BitBucket,..) and not on client side (Intellij for example) – Jasper Huzen Mar 15 '18 at 10:44
  • It's an old answer, but i think this is not the correct answer and should not be marked as excepted for the given question! The question was, how to avoid a commit in IntelliJ and not on server side. I have the same problem, we have protected the master-branch on GitLab but if you forget to create a branch in phpStorm (or whatever JetBrains-IDE you use) the commit is done but the push gets rejected. And the problem is, you now have to rebase your master branch. – MIB Jan 30 '20 at 06:42
  • @MIB git is designed to be distributed. so all clones of a repo are equal. It's up to the project owner to decide which repo is the golden source and usually it's the one that lives on the server. If people insists on committing to master locally it's their choice and they will always find a way to avoid branch restrictions locally. – Karol Dowbecki Jan 30 '20 at 09:58
  • 2
    Yes, but the question was: how to set up IntelliJ, to reject commiting on a specific branch, and not, how to prevent everyone from comming into it. The questioner stated, sometimes a developer forgets about the restriction. IntelliJ accepts the commit, and if the branch is properly set to be restricted, the push gets rejected. Then the developer has to rebase the branch inside IntelliJ. To avoid this, they want to setup a rejection inside IntelliJ. There is already an official Issue about this: https://youtrack.jetbrains.com/issue/IDEA-227205 – MIB Jan 30 '20 at 12:07