I assume you push your feature-branch to your remote anyway, so you don't have to backup anything, since it is backed up on your remote. Just make sure you didn't break anything during rebase before force pushing the feature-branch.
So the workflow would be as follows.
Before rebase:
A -- B -- C <-- main, origin/main
\
X -- Y -- Z <-- branch, origin/branch
After rebase:
main, origin/main
|
A -- B -- C -- X' -- Y' -- Z' <-- branch
\
X -- Y -- Z <-- origin/branch
If everything worked well, you just run git push -f
to update the remote feature branch.
main, origin/main
|
A -- B -- C -- X' -- Y' -- Z' <-- branch, origin/branch
And if it doesn't you hard reset to origin/branch
and you are back at the beginning (git reset --hard origin/branch
).
A -- B -- C <-- main, origin/main
\
X -- Y -- Z <-- branch, origin/branch
This is basically, the greatness of git and maintaining a remote repository, it's not just about collaboration with others, you can also collaborate with your past self :D