HRJ
HRJ

Reputation: 17797

How to prevent rebase of certain branches, such as 'master'

Is there a way to prevent a silly mistake such as rebasing master onto another branch?

It might be possible to undo this by using the reflog, but I would like to avoid the hassle by preventing the rebase in the first place.

Upvotes: 6

Views: 3239

Answers (2)

iurifq
iurifq

Reputation: 116

This gist shows how to use a pre-rebase hook to avoid git rebases the way you want.

https://gist.github.com/uasi/9384329

You would just have to previously configure which branches you want to avoid rebasing through git config

Upvotes: 9

larsks
larsks

Reputation: 312370

There is a pre-rebase git hook:

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.

You could probably use this to implement the functionality you're asking about.

Upvotes: 3

Related Questions