gitgit-branchgit-rebasegit-remoteremote-branch

Is it safe to rebase remote branch if nobody based work on it?


I want push my personal local branch for code review with my peer. My peer doesn't will merge this branch. After code review, I want rebase my personal branch in master branch, and push master branch. Is safe?

The Pro Git book says:

Do not rebase commits that exist outside your repository and that people may have based work on.

I expect this won't be a problem, since nobody based work on this branch. I am correct?


Solution

  • This sentence is a bit confusing, and you need to be very clear about it before you use git rebase:

    After code review, I want rebase my personal branch in master branch, and push master branch.

    The normal wording is "rebase branch A onto branch B". What this really means is "create a new version of branch A, as though you had developed it starting from branch B".

    Branch B is not changed by this action.

    The reason I'm going over this is to make clear what the warning means:

    Do not rebase commits that exist outside your repository and that people may have based work on.

    The commits you are rebasing are branch A - the branch that is going to change as result of the rebase.

    So there are two very different scenarios:


    A smiple rule of thumb I like to use is "who owns this branch?"