This informational message appears when creating the first commit on an orphan branch. Orphan branches intentionally have no parent commits, which is useful for gh-pages, fresh history starts, or separate project histories.
The message "Initial commit on orphan branch - no parent exists" appears when you create the first commit on an orphan branch in Git. This is not an error but rather an informational status indicating that your new branch has no connection to any existing commit history. When you see `(root-commit)` in the git log output, it confirms that this commit is a new starting point with no parent. An orphan branch is created using `git checkout --orphan <branch-name>` or `git switch --orphan <branch-name>`. Unlike regular branches that inherit the full commit history of their parent, orphan branches start with a completely empty history. This is by design and serves specific use cases where you need an isolated branch without any connection to your repository's main history. This behavior is intentional and expected. If you deliberately created an orphan branch, you can proceed normally with your workflow. If you accidentally created an orphan branch when you meant to create a regular branch, you can easily switch to the correct approach.
First, confirm whether you actually wanted an orphan branch. If you did, this message is expected and you can proceed normally.
# Check if you're on an orphan branch (no commits yet)
git status
# Output will show "No commits yet" for a new orphan branchCommon valid use cases for orphan branches:
- Creating a gh-pages branch for GitHub Pages
- Starting fresh without old history
- Separating unrelated code in the same repo
If you intentionally created an orphan branch, simply add your files and commit:
# Add files to the new orphan branch
git add .
# Create the first commit (this will be a root commit)
git commit -m "Initial commit on orphan branch"
# Push the orphan branch to remote
git push -u origin your-orphan-branchThe (root-commit) indicator in the log confirms your orphan branch is set up correctly.
When using git checkout --orphan, files from the previous branch remain staged. To start with a clean slate:
# Remove all staged files inherited from the previous branch
git rm -rf .
# Verify working directory is clean
ls -la
# Now add only the files you want
git add your-new-files/
git commit -m "Initial commit"Note: git switch --orphan automatically clears the working directory, making this step unnecessary.
If you prefer starting with an empty working directory automatically, use git switch instead:
# Creates orphan branch AND clears working directory
git switch --orphan new-branch-name
# Working directory is now empty - add your files
echo "# My Project" > README.md
git add README.md
git commit -m "Initial commit"This is the recommended approach for Git 2.23+ as it's more predictable than git checkout --orphan.
If you accidentally created an orphan branch when you wanted a regular branch:
# Abandon the orphan branch
git checkout main # or master, or your base branch
# Create a regular branch with full history
git checkout -b my-feature-branch
# Or using git switch (Git 2.23+)
git switch -c my-feature-branchThe new branch will have the complete commit history from its parent.
If you created an orphan branch by mistake and want to remove it:
# Switch to another branch first
git checkout main
# Delete the local orphan branch
git branch -D unwanted-orphan-branch
# If already pushed, delete from remote
git push origin --delete unwanted-orphan-branchUse -D (force delete) since the orphan branch has no merge relationship with other branches.
If you need to merge an orphan branch into another branch later:
git checkout main
git merge orphan-branch --allow-unrelated-histories
# Resolve any conflicts that arise
git add .
git commit -m "Merge orphan branch into main"The --allow-unrelated-histories flag is required because Git otherwise refuses to merge branches with no common ancestor.
Common Use Cases for Orphan Branches:
GitHub Pages Deployment:
The gh-pages branch is the most common use case for orphan branches. It allows you to host static site files without including the entire project history:
git checkout --orphan gh-pages
git rm -rf .
# Add your built static files
cp -r dist/* .
git add .
git commit -m "Deploy to GitHub Pages"
git push origin gh-pagesRepository History Cleanup:
For repositories with excessive history (many gigabytes), orphan branches let you create a fresh start while keeping the repository:
git checkout --orphan fresh-start
git add -A
git commit -m "Fresh start - history truncated"
git branch -D main
git branch -m main
git push -f origin main # Warning: destructive operationMulti-Project Repositories:
Some teams use orphan branches to maintain completely separate projects in one repository, each with its own independent history.
CI/CD Considerations:
When working with orphan branches in CI/CD pipelines:
- Shallow clones (--depth 1) work well with orphan branches
- Build tools that rely on git history may behave differently
- Version calculation tools (like GitVersion) may not work as expected
Difference Between checkout --orphan and switch --orphan:
| Command | Working Directory | Staging Area |
|---------|------------------|--------------|
| git checkout --orphan | Keeps files from previous branch | Files are staged |
| git switch --orphan | Empties the directory | Nothing staged |
For most use cases, git switch --orphan provides a cleaner experience.
warning: BOM detected in file, this may cause issues
UTF-8 Byte Order Mark (BOM) detected in file
fatal: Server does not support --shallow-exclude
Server does not support --shallow-exclude
warning: filtering out blobs larger than limit
Git partial clone filtering large blobs warning
fatal: Server does not support --shallow-since
Server does not support --shallow-since in Git
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server