Search code examples
gitgit-branchgit-repo

How to create a new branch from another repository?


I have a repository (repo1) with a master branch and another repository (repo2) with a master branch. Now I want to create a new branch in repo1 from repo2 with all commits history.


My expected result:

repo2
----
|
 \
  master


repo1
----------
|         |
 \         \
  master    master-from-repo2

Solution

  • cd repo1
    git fetch repo2 master:master-from-repo2
    

    Remote branch master is fetched from repo2 into local branch master-from-repo2.