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?

4
  • What did you try? Just create a new project, set the remote in your checkout to the new project and push ? Commented Mar 13, 2018 at 9: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. Commented Mar 13, 2018 at 9:39
  • Yes, you can simply push only branch A to the remote of project C Commented Mar 13, 2018 at 9:54
  • Possible duplicate of Detach (move) subdirectory into separate Git repository Commented Mar 13, 2018 at 11:10

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.