1

I have a repository in github with X number of branches and a repository in a closed network.

I need to move all of the repository to the one on the closed network. How do I clone all the branches (not just the default master), so I could then push it to the closed-network one with all the branches existing.

Entering the repo binary is not the issue here.

I want the same result as if I cloned my repo and did git branch to each branch, so it would be initialized locally.

TriskalJM
  • 2,123
  • 1
  • 16
  • 18
levich
  • 338
  • 1
  • 4
  • 14
  • [Here is the detail answer click here](https://stackoverflow.com/questions/67699/how-to-clone-all-remote-branches-in-git?page=1&tab=votes#tab-top) – Suneel Kumar Jul 05 '17 at 11:13
  • Possible duplicate of [How to clone all remote branches in Git?](https://stackoverflow.com/questions/67699/how-to-clone-all-remote-branches-in-git) – Ebrahim Poursadeqi Jul 05 '17 at 11:46

3 Answers3

3

If it's ok to not create the remote branch refs, and if the clone can be "bare" (no default working tree), then you can use

git clone --mirror url

But you said you want the same result as cloning and then checking out each branch. Taken literally, that would mean a non-bare repo that has both the remote refs and the local branches. To do that you could do this:

First, clone normally and cd into the new clone

git clone url new-repo
cd new-repo

Now force detached head state to ensure no "current branch" problems

git checkout `git rev-parse HEAD`

Now get the local branches set up

git fetch origin +refs/heads/*:refs/heads/*

And now of course you can check out whatever branch you should be on, e.g.

git checkout master
Mark Adelsberger
  • 32,904
  • 2
  • 24
  • 41
1

Once created something like that. Hopefully it still works. Perhaps it could help you: https://github.com/srfrnk/fetch-all

srfrnk
  • 2,289
  • 1
  • 14
  • 30
0

There's a git-clone option --mirror which sets up all remotely tracked branches. But, --mirror also implies --bare option, ie. the clone will will not be created as a working copy and you cannot checkout the branches. Therefore the directory is changed to a working directory afterwards.

$ git clone --mirror original-repo.git /path/cloned-directory/.git
$ cd /path/cloned-directory
$ git config --bool core.bare false
$ git checkout anybranch

Git FAQ: How do I clone a repository with all remotely tracked branches?

  • 1
    Careful: if you use the four lines shown above, your `fetch` configuration entry will still be set up to *overwrite* local branches. – torek Jul 05 '17 at 15:04