Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3451460
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:08:49+00:00 2026-05-18T09:08:49+00:00

While helping a friend with a git problem today, I had to introduce a

  • 0

While helping a friend with a git problem today, I had to introduce a
branch that needed to be totally separate from the master branch.
The contents of this branch really had a different origin from what
had been developed on the master branch, but they were going to be
merged into the master branch at a later time.

I remembered from reading John Wiegley’s Git from the bottom
up
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:

So we got rid of all files in the index …

$ git rm -rf .

… extracted directories and files from a tarball, added those to the
index …

$ git add .

… and created a tree object …

$ git write-tree

(git-write-tree told us the sha1sum of the created tree object.)

Then, We committed the tree, without specifying parent commits…

$ echo "Imported project foo" | git commit-tree $TREE

(git-commit-tree told us the sha1sum of the created commit object.)

… and created a new branch that points to our newly created
commit.

$ git update-ref refs/heads/other-branch $COMMIT

Finally, we returned to the master branch to continue work there.

$ git checkout -f master

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. Is there an easier way of creating a
new branch that is entirely unrelated to everything that has happened
in the repository so far?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:08:50+00:00Added an answer on May 18, 2026 at 9:08 am

    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.

    git checkout now supports the --orphan option. From the man page:

    git checkout [-q] [-f] [-m] --orphan <new_branch> [<start_point>]

    Create a new orphan branch, named
    <new_branch>, started from
    <start_point> 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.

    This doesn’t do exactly what the asker wanted, because it populates the index and the working tree from <start_point> (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, git reset --hard doesn’t work, but git rm -rf . can be used instead (I believe this is equivalent to rm .git/index; git clean -fdx given in other answers).


    In summary:

    git checkout --orphan newbranch
    git rm -rf .
    <do work>
    git add your files
    git commit -m 'Initial commit'
    

    I left <start_point> 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 Artem’s answer, just without resorting to scary plumbing commands.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been away from inheritance for a while and need a little helping hand.
My problem is related to getting the correct mouse co-ordinates from SFML while using
thank you all so very much for helping. It's seemingly such an easy task,
I asked a question on helping me with this question about a week ago
I'm looking for some advice if possible. PHP isn't the main language I write
I am usign Eclipse PDT Helios and it sometimes freezes for 2-3 seconds even
I'd like to show a form (the form has a box where you type
I need some guidance on how best to run this program. Im trying to
When people write an article, they submit a photo to illustrate the event. But,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.