Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can create a detached <strong>master</strong> branch using only porcelain Git commands:</p> <pre><code>git init touch GO_AWAY git add GO_AWAY git commit -m "GO AWAY - this branch is detached from reality" </code></pre> <p>That gives us a <strong>master</strong> branch with a rude message (you may want to be more polite). Now we create our "real" branch (let's call it <strong>trunk</strong> in honour of SVN) and divorce it from <strong>master</strong>:</p> <pre><code>git checkout -b trunk git rm GO_AWAY git commit --amend --allow-empty -m "initial commit on detached trunk" </code></pre> <p>Hey, presto! <strong>gitk --all</strong> will show <strong>master</strong> and <strong>trunk</strong> with no link between them.</p> <p>The "magic" here is that <strong>--amend</strong> causes <strong>git commit</strong> to create a new commit with the same parent as the current HEAD, then make HEAD point to it. But the current HEAD doesn't have a parent as it's the initial commit in the repository, so the new HEAD doesn't get one either, making them detached from each other.</p> <p>The old HEAD commit doesn't get deleted by <strong>git-gc</strong> because refs/heads/master still points to it.</p> <p>The <strong>--allow-empty</strong> flag is only needed because we're committing an empty tree. If there were some <strong>git add</strong>'s after the <strong>git rm</strong> then it wouldn't be necessary.</p> <p>In truth, you can create a detached branch at any time by branching the initial commit in the repository, deleting its tree, adding your detached tree, then doing <strong>git commit --amend</strong>.</p> <p>I know this doesn't answer the question of how to modify the default branch on the remote repository, but it gives a clean answer on how to create a detached branch.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload