I've cloned a large, well-maintained repository. By accident I used the -b
flag when checking out a different branch. Git says "Switched to a new branch". Was the pre-existing branch overwritten, is git's output misleading, or did I make another mistake?
Was the preexisting branch overwrote,
No.
The default branch has been checked out, and a new local branch has been created from its HEAD.
You can see all the branches with:
git branch -a
Simply switch back to the upstream branch of your choice with
git checkout -b aBranch --track origin/aBranch
# if the local branch was already there
git checkout -B aBranch --track origin/aBranch
Note that if you have work in progress, you need first to go a git stash
, as explained in "To git checkout
without overwriting data".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With