Ahmad
Ahmad

Reputation: 2190

Copying some branches of a repository into a new repository

We have a huge git repository (say it A )that contains many branches. I want to create a new smaller repository (say it B) that will contain few branches of A.

What I know is as follows

  1. Clone some branches from repository A to local
  2. Push these branches to repository B.

Don't we have some method to copy these branches directly from repository A to B?. Or some improvement to the above mthod?

Upvotes: 1

Views: 34

Answers (1)

VonC
VonC

Reputation: 1325976

If you have direct access to repo A, you can directly the branch you want to a new repo B.

But if you need to clone A first, then a concrete example exists in "Clone just the stable and one other branch in git?", and uses the same tip than the question mentioned by mnagel, with git remote:

 cd B
 git init .
 git remote add -f -t remote-branch1 -t remote-branch1 remote-name remote-url

Note the -f which, when used with git remote add, will immediately fetch remote_name.

Upvotes: 1

Related Questions