How to create a new branch from another repository?
Asked Answered
C

1

12

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
Compression answered 13/1, 2019 at 12:41 Comment(0)
K
12
cd repo1
git fetch repo2 master:master-from-repo2

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

Kaz answered 13/1, 2019 at 13:31 Comment(5)
Thank you, it works fine. If repo2 has another branch and when I want to get this branch can I do it: any-branch-in-repo2:master-from-repo2 instead of master:master-from-repo2?Compression
Yes, any branch will do.Kaz
Thanks for the answer. But what if the repo2 that I want to fetch is local?Retardment
@Retardment Shouldn't matter, git fetch fetches over any supported protocol, git://, ssh://, https://, file:/// (local). Just add repo2 as a remote: git remote add repo2 file:///path/to/local/repoKaz
@Kaz Thank you. Just fetched a local repo successfully.Retardment

© 2022 - 2024 — McMap. All rights reserved.