JJD
JJD

Reputation: 51884

How to protect a local master branch from being rebased?

I want to protect a specific local branch (e.g. master) from being rebased accidentally. I know how to do this on the server side. Bitbucket has a configuration as shown in the screenshot.

Prevent history rewrite

How can I protect a local branch (e.g. master) from being rebased as in ...?

$ git rebase feature master

Upvotes: 1

Views: 294

Answers (2)

RomanPerekhrest
RomanPerekhrest

Reputation: 92884

Go through the following steps:

  • add specific setting to your git config list with the command: git config branch.master.rebaselock true (along with master could be any other branch)
  • use pre-rebase git hook by Uasi: https://gist.github.com/uasi/9384329

Upvotes: 3

Vampire
Vampire

Reputation: 38734

pre-rebase hook is what you're after.

Here a quote from https://git-scm.com/docs/githooks:

pre-rebase

This hook is called by git rebase and can be used to prevent a branch from getting rebased. The hook may be called with one or two parameters. The first parameter is the upstream from which the series was forked. The second parameter is the branch being rebased, and is not set when rebasing the current branch.

Upvotes: 2

Related Questions