LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

git-fresh-branch

Create orphan branch with no commit history

TLDR

Create orphan branch
$ git fresh-branch [branch_name]
copy

SYNOPSIS

git fresh-branch name

DESCRIPTION

git fresh-branch creates a new orphan branch with no parent commits or history connection to the existing repository. It repoints HEAD at the new (as yet nonexistent) branch ref, clears the index, and runs git clean -fdx on the working tree, leaving a completely clean slate within the same repository.The primary use case is gh-pages branches for GitHub Pages hosting, where documentation or website content lives in the same repository but shares no history with the codebase. Other uses include documentation branches, experimental branches, or vendor branches for third-party code.If the working tree has untracked changes, the command prompts for confirmation before proceeding, since git clean -fdx deletes them irrecoverably.

PARAMETERS

NAME

Name of the new branch to create.

INSTALL

sudo apt install git
copy
sudo dnf install git
copy
sudo pacman -S git
copy
sudo apk add git
copy
sudo zypper install git
copy
brew install git
copy
nix profile install nixpkgs#git
copy

CAVEATS

Part of git-extras package. Destroys untracked files and the index without a real backup; commit or stash anything you want to keep before running it. Equivalent in effect to git checkout --orphan name followed by clearing the index and working tree.

SEE ALSO

RESOURCES

Copied to clipboard
Kai