Test with New Orphan Branch
In this step, we will create a new "orphan" branch. An orphan branch is a branch that starts with no history from previous branches. It's like starting a completely new timeline in your time machine. This is useful for things like documentation branches or gh-pages branches for websites, where you don't want the history of your main code to be included.
Make sure you are in the ~/project/my-time-machine
directory.
cd ~/project/my-time-machine
Now, let's create a new orphan branch called new-start
:
git checkout --orphan new-start
You should see output similar to this:
Switched to a new branch 'new-start'
We have now switched to the new-start
branch. Notice that the files from the master
branch are still present in your working directory. This is because git checkout --orphan
prepares your working directory and index for a new root commit, but it doesn't remove the existing files.
Let's check the status:
git status
You should see something like this:
On branch new-start
Untracked files:
(use "git add <file>..." to include in what will be committed)
message.txt
nothing added to commit but untracked files present (use "git add" to track)
Git sees message.txt
as an untracked file because the history of the new-start
branch is completely separate from master
.
To truly start fresh on this orphan branch, we typically remove the old files and then add the new content for this branch. Let's remove the message.txt
file:
rm message.txt
Now, let's check the status again:
git status
You should see:
On branch new-start
No commits yet
nothing to commit (create/copy files and use "git add" to track)
The working directory is now clean, and we are ready to create the first commit on our new, independent timeline.
Let's create a new file specific to this branch:
echo "This is a fresh start!" > readme.md
Add the new file to the staging area:
git add readme.md
And finally, create the first commit on the new-start
branch:
git commit -m "Initial commit for new-start branch"
You should see output similar to this:
[new-start (root-commit) a1b2c3d] Initial commit for new-start branch
1 file changed, 1 insertion(+)
create mode 100644 readme.md
Notice that this commit is also a "(root-commit)", just like the first commit on the master
branch. This confirms that it has no parent and is the beginning of a new history.
Now, let's look at the log for this branch:
git log --pretty=oneline
You should see only the single commit we just made:
a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9 (HEAD -> new-start) Initial commit for new-start branch
This demonstrates that the new-start
branch has its own independent history, separate from the master
branch.