I cloned a repo from github, made a new branch, pushed back up to github, then deleted the repo locally, and finally cloned again. Now I'd like to restore my branches back to how they were before I deleted the the repo locally, also along the way I'd like to learn more about what's going on with my situation and how it applies to the notions of HEAD
, detached head state, remotes, and refs/heads
.
I know the two branches of interest (mbigras
and mcb-fix-type
) are still there but they have been renamed:
atom-pane-manager git:master ❯ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/mbigras
remotes/origin/mcb-fix-typo
So initially I thought I could just rename the remotes/origin/mbigras
branch to mbigras
and be done but I got the following error:
atom-pane-manager git:master ❯ git branch -a | grep mbigras | pbcopy
atom-pane-manager git:master ❯ git branch -m remotes/origin/mbigras mbigras
error: refname refs/heads/remotes/origin/mbigras not found
fatal: Branch rename failed
There's several things I'm curious about:
- Why can't I rename the branch?
- Why is
refs/heads/
included on the branch name in the error message?
Also looking at the branches I'm also wondering:
- What do the
remotes/origin/HEAD
andremotes/origin/master
branches mean?
I was poking around in .git
trying to make heads or tails of the situation
atom-pane-manager git:master ❯ tree .git/refs
.git/refs
├── heads
│ └── master
├── remotes
│ └── origin
│ └── HEAD
└── tags
4 directories, 2 files
I was expecting to at least find remotes/origin/mbigras
and remotes/origin/mcb-fix-typo
in remotes
but they're not, which is also confusing.
I also read another post that talks about "detached head state" I'm not sure if that's aplicable to my situation but the post did go over the git rev-parse
command which might help shed some light:
atom-pane-manager git:master ❯ git rev-parse master
73b3c240ff9b35d760d8e4302308d3c0e725fc76
atom-pane-manager git:master ❯ git rev-parse HEAD
73b3c240ff9b35d760d8e4302308d3c0e725fc76
atom-pane-manager git:master ❯ git rev-parse remotes/origin/HEAD
73b3c240ff9b35d760d8e4302308d3c0e725fc76
atom-pane-manager git:master ❯ git rev-parse remotes/origin/master
73b3c240ff9b35d760d8e4302308d3c0e725fc76
atom-pane-manager git:master ❯ git rev-parse remotes/origin/mbigras
9a25755b0175ba2a3548b439ffdb12b8010e74a6
atom-pane-manager git:master ❯ git rev-parse remotes/origin/mcb-fix-typo
6d235be40c7223fda7a8a6dbdf8b2fd7336e3d00
From these results it looks like HEAD
, master
, remotes/origin/HEAD
, and remotes/origin/master
all point to the same place, which makes sense because they're pointing to the last commit:
atom-pane-manager git:master ❯ git log --pretty=oneline -n 1 | pbcopy
# => 73b3c240ff9b35d760d8e4302308d3c0e725fc76 Prepare 1.0.1 release
And the two mystery branches do exist ...somewhere.
So I'm confused about what the heck is going on, and specifically the three questions mentioned above. I'd especially love an answer to include a visual representation of what is happening. Thanks