2

There are some similar posts on SO related to git repository export and import, but all answers are not complete. So I am asking separate question here.

I am using EGIT in eclipse to work on git SCM.

How I can export the git repository to a zip file/folder(with all branches, tags and history) and import the same repository back in Eclipse?

I tried,

git archive HEAD --format=zip >~/abc.zip but while importing back in eclipse its not working.

Are there any other ways for importing and exporting git repositories?


Edit

After looking @VonC answer, I did this

  1. git bundle create ~/abc.bundle --all

  2. git bundle list-heads ~/abc.bundle

      refs/heads/master
      refs/remotes/origin/branch1
      refs/remotes/origin/branch1
      refs/remotes/origin/branch3
      refs/remotes/origin/master 
      refs/remotes/origin/branch4
      .....
      refs/tags/tag1
      refs/tags/tag2
      refs/tags/tag3
       ....
  3. git clone -b master ~/abc.bundle ~/newrepo/xyz/

But when I tried to import this git repo in eclipse I am getting only master branch as while cloning I used master. Is it possible to clone all the branches in a single command?

Chandrayya G K
  • 8,719
  • 5
  • 40
  • 68

1 Answers1

2

Another way, which actualy does preserve the full history, is git bundle (see "Backup a Local Git Repository").

cd /path/to/your/repo
git bundle create ../repo.bundle --all

However, you will have to clone it again before EGit can see the exported/imported repo, because EGit doesn't support yet bundle files as repo.


when I tried to import this git repo in eclipse I am getting only master branch as while cloning I used master. Is it possible to clone all the branches in a single command?

Do a git branch -avvv in your cloned repo (the one cloned from the bundle).
You should see all your remote branches (origin/xxx).

Eclipse should then be able to list and make a new branch based on one of those remote tracking branches as in "How do I create a proper new local and remote branch combination in EGit?".

To restore all the branches from the bundle, see "restore all refs from git bundle":
You need to mirror clone it.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250