I want to rebase and checkout a branch onto the current branch without checking it out first. This saves time checkout out an old repository state and recompiling the files it touches.
For example, I have this:
A -> B -> C (HEAD -> main)
\
D -> E (old)
I want the following. Basically checking out old
and rebasing on top of main
.
A -> B -> C (main) -> D -> E (HEAD -> old)
I would normally run:
git checkout old
git rebase main
The problem is I was working on the old
branch months ago. Checking it out will touch many files. The repository is huge and I'll need to spend hours recompiling if I do that. What I really want to do is the following:
# Don't update 'main'
git checkout --detach
# Automatically cherry-picks commits after the common ancestor,
# just like a 'rebase' from that branch would do.
git cherry-pick main..old
# Update the branch ref
git branch -f old HEAD
# Check out the "rebased" branch
git checkout old
Is there a shorter way of doing this?