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

GitBranchExtract

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

You can simply push a branch to a new repository. All of its 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:new-branch-name

For a new repository, new-branch-name is typically master.

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

Solution 2 - Git

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAupajoView Question on Stackoverflow
Solution 1 - GitCB BaileyView Answer on Stackoverflow
Solution 2 - GitDamonView Answer on Stackoverflow