Reset other branch to current without a checkout
The workflows you describe are not equivalent: when you perform reset --hard
you lose all the changes in the working tree (you might want to make it reset --soft
).
What you need is
git update-ref refs/heads/OtherBranch refs/heads/CurrentBranch
Set otherbranch
to point at the same commit as currentbranch
by running
git branch -f otherbranch currentbranch
The -f
(force) option tells git branch
yes, I really mean to overwrite any existing otherbranch
reference with the new one.
From the documentation:
-f
--forceReset to if exists already. Without -f git branch refuses to change an existing branch.