Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 526
HRJ Avatar asked Jul 17 '15 02:07

HRJ


People also ask

How do I stop rebasing master?

You can run git rebase --abort to completely undo the rebase. Git will return you to your branch's state as it was before git rebase was called. You can run git rebase --skip to completely skip the commit. That means that none of the changes introduced by the problematic commit will be included.

How do I stop rebasing branch?

If you prefer to skip this patch, run "git rebase --skip" instead. To check out the original branch and stop rebasing, run "git rebase --abort".

When should you avoid rebasing a branch?

If you use pull requests as part of your code review process, you need to avoid using git rebase after creating the pull request. As soon as you make the pull request, other developers will be looking at your commits, which means that it's a public branch.

Does rebase affect master?

git rebase origin/master will merge in the requested branch ( origin/master in this case) and apply the commits that you have made locally to the top of the history without creating a merge commit (assuming there were no conflicts).


2 Answers

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

like image 89
iurifq Avatar answered Sep 23 '22 17:09

iurifq


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.

like image 43
larsks Avatar answered Sep 22 '22 17:09

larsks