Skip to content

Utility to split a Git branch into multiple branches based on arbitrary pathspecs

Notifications You must be signed in to change notification settings

djpohly/git-split-branch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 

Repository files navigation

git-split-branch

git-split-branch splits a single git branch into multiple branches, each of which contains a specified set of the original branch's files and only the commits which affect that set.

This is a similar effect to what git-filter-branch would produce by using an index filter to select specific files. (In fact, git-split-branch is obviously and unabashedly modified from git-filter-branch.) But unlike...

  • git-subtree, it can split off an arbitrary set of files, not just a subdirectory.
  • git-filter-branch, it can create multiple branches.
  • multiple git-filter-branch calls, it only requires one pass over the commit history.
  • other scripts that wrap git-filter-branch, see one of the previous two points.

In addition, git-split-branch assigns the leftover files to a "remainder" branch or rewrites the original source branch to contain only the leftovers.

On the other hand, git-filter-branch allows for other filters to be applied, while git-split-branch is single in its purpose.

Install

Download and place git-split-branch somewhere in your $PATH, or symlink from its git repository to your $PATH.

No other setup is required before invoking as git split-branch.

Usage

git split-branch [-d <workdir>] [-r <remainder>] <source> <dest1> <paths1>... [ -- <dest2> <paths2>... ]...

This command will split the contents of the <source> branch, creating branch <dest1> to contain only files matching <paths1>, branch <dest2> to contain <paths2>, and so forth. The remaining unsplit files will be written to branch <remainder> if the -r flag is given; otherwise <source> will be rewritten to contain the remaining files only.

As with git-filter-branch, the directory in which work is done can be specified (e.g. on a tmpfs) with -d.

Motivation

This utility was motivated by the desire to migrate a large $HOME repository to vcsh. This repository contained seven years of configuration, grad school work, personal writings, code for side projects, etc. It had originally been hosted in Subversion as a single, large repository, and it was later converted to Git via git-svn but not restructured into smaller, more logical units. git-split-branch was written to split this repository into smaller units without having to iterate seven years of commits for every split.

The tool took 24 minutes to split 2750 commits into 60 branches.

About

Utility to split a Git branch into multiple branches based on arbitrary pathspecs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages