Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is a new feature (since V1.7.2) which makes this task a little more high-level than what's in any of the other answers.</p> <p><code>git checkout</code> now supports the <strong><code>--orphan</code></strong> option. From the <a href="https://www.kernel.org/pub/software/scm/git/docs/git-checkout.html" rel="noreferrer">man page</a>:</p> <p><code>git checkout [-q] [-f] [-m] --orphan &lt;new_branch&gt; [&lt;start_point&gt;]</code></p> <blockquote> <p>Create a new <em>orphan</em> branch, named &lt;new_branch&gt;, started from &lt;start_point&gt; and switch to it. The first commit made on this new branch will have no parents and it will be the root of a new history totally disconnected from all the other branches and commits.</p> </blockquote> <p>This doesn't do <em>exactly</em> what the asker wanted, because it populates the index and the working tree from <code>&lt;start_point&gt;</code> (since this is, after all, a checkout command). The only other action necessary is to remove any unwanted items from the working tree and index. Unfortunately, <code>git reset --hard</code> doesn't work, but <code>git rm -rf .</code> can be used instead (I believe this is equivalent to <code>rm .git/index; git clean -fdx</code> given in other answers).</p> <hr> <p><strong>In summary:</strong></p> <pre><code>git checkout --orphan newbranch git rm -rf . &lt;do work&gt; git add your files git commit -m 'Initial commit' </code></pre> <p>I left <code>&lt;start_point&gt;</code> unspecified because it defaults to HEAD, and we don't really care anyway. This sequence does essentially the same thing as the command sequence in <a href="https://stackoverflow.com/questions/1384325/in-git-is-there-a-simple-way-of-introducing-an-unrelated-branch-to-a-repository/1384336#1384336">Artem's answer</a>, just without resorting to scary plumbing commands. </p>
    singulars
    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. 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