Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Called git checkout -b branchname on pre-existing branch; was old one overwritten?

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?

like image 681
mda Avatar asked Jan 21 '13 06:01

mda


1 Answers

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".

like image 132
VonC Avatar answered Oct 19 '22 20:10

VonC