Restore branches after cloning
<p>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 <code>HEAD</code>, detached head state, remotes, and <code>refs/heads</code>.</p>

<p>I know the two branches of interest (<code>mbigras</code> and <code>mcb-fix-type</code>) are still there but they have been renamed:</p>

<pre><code>atom-pane-manager git:master ❯ git branch -a
* master
  remotes/origin/HEAD -&gt; origin/master
  remotes/origin/master
  remotes/origin/mbigras
  remotes/origin/mcb-fix-typo
</code></pre>

<p>So initially I thought I could just rename the <code>remotes/origin/mbigras</code> branch to <code>mbigras</code> and be done but I got the following error:</p>

<pre><code>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
</code></pre>

<p>There's several things I'm curious about:</p>

<ol>
<li>Why can't I rename the branch?</li>
<li>Why is <code>refs/heads/</code> included on the branch name in the error message?</li>
</ol>

<p>Also looking at the branches I'm also wondering:</p>

<ol start="3">
<li>What do the <code>remotes/origin/HEAD</code> and <code>remotes/origin/master</code> branches mean?</li>
</ol>

<p>I was poking around in <code>.git</code> trying to make heads or tails of the situation   </p>

<pre><code>atom-pane-manager git:master ❯ tree .git/refs
.git/refs
├── heads
│   └── master
├── remotes
│   └── origin
│       └── HEAD
└── tags

4 directories, 2 files
</code></pre>

<p>I was expecting to at least find <code>remotes/origin/mbigras</code> and <code>remotes/origin/mcb-fix-typo</code> in <code>remotes</code> but they're not, which is also confusing. </p>

<p>I also read <a href="https://stackoverflow.com/questions/5772192/how-can-i-reconcile-detached-head-with-master-origin">another post</a> that talks about "detached head state" I'm not sure if that's aplicable to my situation but the post did go over the <code>git rev-parse</code> command which might help shed some light:</p>

<pre><code>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
</code></pre>

<p>From these results it looks like <code>HEAD</code>, <code>master</code>, <code>remotes/origin/HEAD</code>, and <code>remotes/origin/master</code> all point to the same place, which makes sense because they're pointing to the last commit:</p>

<pre><code>atom-pane-manager git:master ❯ git log --pretty=oneline -n 1 | pbcopy
# =&gt; 73b3c240ff9b35d760d8e4302308d3c0e725fc76 Prepare 1.0.1 release
</code></pre>

<p>And the two mystery branches do exist ...somewhere.</p>

<p>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 </p>