views:

126

answers:

2

I have a branch that I'd like to move into a separate Git repository, and ideally keep that branch's history in the process. So far I've been looking at git filter-branch, but I can't make out whether it can do what I want to do.

How do I extract a Git branch out into its own repository?

+1  A: 

This will keep the history of all the branches, but make your copy point to the one branch in particular:

git clone -b newbranch CurrentRepo NewRepo

This does not 'move' anything, just makes a copy.

Buckwad
Worth noting that `clone -b` is new. It requires git >= 1.6.5 (released October 2009).
Charles Bailey
I had trouble getting this to work, but that was before I saw the message from Charles Bailey.
Aupajo
+6  A: 

You can simply push a branch to a new repository. All it's history will go with it. You can then choose whether to delete the branch from the original repository.

e.g.

git push url://to/new/repository.git branch-to-move

Creating a new repository empty repository can be done with git init.

Charles Bailey
Just in case anyone's wondering, I substituted the URL with the path to a Git repository directory, and that worked perfectly.
Aupajo