Note that there are some explanatory texts on larger screens.

plurals
  1. POIn git, is there a simple way of introducing an unrelated branch to a repository?
    primarykey
    data
    text
    <p>While helping a friend with a git problem today, I had to introduce a branch that needed to be totally separate from the <code>master</code> branch. The contents of this branch really had a different origin from what had been developed on the <code>master</code> branch, but they were going to be merged into the <code>master</code> branch at a later time.</p> <p>I remembered from reading John Wiegley's <a href="http://ftp.newartisans.com/pub/git.from.bottom.up.pdf" rel="noreferrer">Git from the bottom up</a> how branches are essentially a label to a commit that follows a certain convention and how a commit is tied to a tree of files and, optionally to parent commits. We went to create a parentless commit to the existing repository using git's plumbing:</p> <p>So we got rid of all files in the index ...</p> <pre><code>$ git rm -rf . </code></pre> <p>... extracted directories and files from a tarball, added those to the index ...</p> <pre><code>$ git add . </code></pre> <p>... and created a tree object ...</p> <pre><code>$ git write-tree </code></pre> <p>(<code>git-write-tree</code> told us the sha1sum of the created tree object.)</p> <p>Then, We committed the tree, without specifying parent commits...</p> <pre><code>$ echo "Imported project foo" | git commit-tree $TREE </code></pre> <p>(<code>git-commit-tree</code> told us the sha1sum of the created commit object.)</p> <p>... and created a new branch that points to our newly created commit.</p> <pre><code>$ git update-ref refs/heads/other-branch $COMMIT </code></pre> <p>Finally, we returned to the <code>master</code> branch to continue work there.</p> <pre><code>$ git checkout -f master </code></pre> <p>This seems to have worked as planned. But this is clearly not the kind of procedure I would recommend to someone who is just getting started using git, to put it mildly. <strong>Is there an easier way of creating a new branch that is entirely unrelated to everything that has happened in the repository so far?</strong></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. 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