I'm on my branch (not master) and I need to get the latest version of master
locally. I do next still staying on my branch:
git fetch
git rebase origin/master master
After this master
is checked out and I need to go back to my branch. Is there any way to avoid the check out local master
during rebase?
The short answer is unfortunately no.
From the doc :
If is specified, git rebase will perform an automatic git switch before doing anything else. Otherwise it remains on the current branch.
This is the same for merges : you only work on a checked out branch for these operations, since they theoretically could result in a conflicting state and would then need to be resolved on the spot.
A sort of workaround would be to chain (with &&
to stop if the rebase returns an error) the subsequent checkout back in an alias.
# fm for "fresh master"
git config --global alias.fm '!git fetch && git rebase origin/master master && git checkout -'