0

I wanted to branch off my master into a new branch, say new-branch. However, I accidentally ran git checkout -b add new-branch.

Now I cannot view any of my other branches or checkout to my origin master. The command seems to have created a new repo locally.

I've tried using git revert to fix this, to no avail. I would like to know how to get to my origin repo and delete the submodule.

4
  • The command you stated in your first paragraph will only create a new branch called add from an existing ref called new-branch. If new-branch is an unknown ref, the command should fail ("fatal: 'new-branch' is not a commit and a branch 'add' cannot be created from it").
    – knittl
    Commented Sep 9, 2019 at 19:30
  • That is what I expected but it created a submodule. Commented Sep 9, 2019 at 19:33
  • @BeulahAkindele (just a sidenote) You actually wanted to name a branch add? If so, this is a really bad idea. There are billions of words or word combinations. Only a few dozens are used for git commands themselves. Don't shoot yourself in the foot by choosing one of them as a branch name. Commented Sep 9, 2019 at 19:37
  • @RomainValeri No, I don't mean I want to name a branch "add", but I see where the misunderstanding stems from. I meant I did not expect the command to execute successfully as knittl said in her comment. Commented Sep 9, 2019 at 21:01

1 Answer 1

2

I'm thinking I should just delete the question but I was just in the wrong directory.

So to get my old branches, I just cd into the appropriate directory and to delete the submodule git rm --cached unintended-branch-name.

1
  • But thanks for the feedback :-) Useful to finally understand what was going on, but not everyone does it. Commented Sep 9, 2019 at 19:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.