0

Some time ago we made a branch from our master branch in Git. Currently, this branch has diverged so much that it makes no sense merging it into the master and we consider creating a new project out of it.

Is there any Git functionality that would allow us creating a new independent project out of this branch, keeping all the history?

daniel sp
  • 937
  • 1
  • 11
  • 29
  • What did you try? Just create a new project, set the remote in your checkout to the new project and push ? – marcolz Mar 13 '18 at 09:34
  • Hmm... Maybe I was not clear enough. In plain words, what I need is that a branch A from a project B becomes itself a totally independent project C. I don't see how your suggestion is going to help me. – daniel sp Mar 13 '18 at 09:39
  • Yes, you can simply push only branch A to the remote of project C – marcolz Mar 13 '18 at 09:54
  • Possible duplicate of [Detach (move) subdirectory into separate Git repository](https://stackoverflow.com/questions/359424/detach-move-subdirectory-into-separate-git-repository) – phd Mar 13 '18 at 11:10

1 Answers1

1

You can use:

git clone --branch A --single-branch B C

--branch tells Git to use branch A as the current branch in the new repo (instead of the master branch of the original repo).

--single-branch tells it to copy into the clone only the commits that are reachable from the current branch (set here using --branch).

B is the original repository (a local directory or an URL), C is the local directory where to create the clone.

In the new repo, Git sets the original repo (B) as the origin remote. If you don't need this link you can remove it any time: just run git remote remove origin in the new repo.

axiac
  • 68,258
  • 9
  • 99
  • 134