In a git repository everything normally  starts with an initial commit and all other commits are ancestors of this first commit. But is it possible to create a second initial commit or even a third? Another initial commit with a complete different working directory? Yes it is.

Git provides a convenience command to create an independent branch.

Even if a simple git command exists I want to dive into the depth of git now and use low-level commands to do the same in order to show you how git works internally.

Create an independent branch step by step

Lets assume you have checked out some branch, e.g. the master branch. The symbolic ref HEAD will point to ref: refs/heads/master and refs/heads/master is just a file that contains the commit id of the master branch.
simple_repository

Now if you just do a git commit, git will

  1. create a new commit object
  2. set the parent to the commit object that HEAD points to (master)
  3. update the ref that the symbolic ref HEAD points to (master)

new_commit

So if you want to create a another initial commit you must update the symbolic-ref HEAD and point it to something else.

change_symbolic_ref_HEAD

Note: Since the ref secondMaster  does not exist yet it is displayed transparent.

Now that you have changed the symbolic ref HEAD to point to the nonexistent ref refs/heads/secondMaster you are ready to create a new initial commit. But changing the symbolic ref HEAD does not change the staging area. Since you  were on master before you changed the symbolic-ref HEAD, the staging area still contains the tree object of the master branch. You can see this if we do a git status.

At this point you can just take the tree object of the master and commit it as a new initial commit or you can clear the staging area and working direcotry to begin a new working directory structure.

If you want a clean staging area and working directory you can do a simple git reset, because HEAD does not point to any commit and therefore git reset will clear the staging area.

Now that the staging area is cleared you can also clear the working directory.

The working directory is clean now and you can create new files, add them to the staging area and finally commit them.

new_initial_commit

The commit that is created is completely independet of all other commits in the current repository and you can see this in the log.