I have a local git repo that I created from an svn repo:
$ git svn clone -s svn:...
I then created a backup remote and pushed everything to it:
$ git remote add backup git@myhost:mybackup.git
$ git push --mirror backup
Now, when I try to clone from my backup, it is missing all svn tags and branches.
$ git clone git@myhost:mybackup.git
$ cd mybackup
$ git branch -a
* master
origin
remotes/origin/HEAD -> origin/master
remotes/origin/master
How do I clone the repo with all tags and branches?
The only way I have found is to mirror the repo:
$ git clone --mirror git@myhost:mybackup.git
This creates a local mybackup.git
directory, which knows about all tags/branches (I can use tab completion to get the entire list) but it is not a valid usable repo:
$ git checkout mytag
fatal: This operation must be run in a work tree
There must be command line option to truly clone the repo with all branches/tags???
I have found several related questions here but none of the answers work for this situation. I assume the difference is that my clone was created with --mirror
?
After a lot of searching, I finally found an answer...
Now a
git branch -a
shows all of my remote branches.I'm not sure if the
git init
is needed here or if it is only needed in thegit init --bare
variant (see the commented out lines in the shell script below), but I am sure that it harms nothing to leave it in if it is not needed.My main reason in doing this is to get my SVN tags/branches copied over rather than only having
master
pointing to SVNtrunk
and without having to parse the entire SVN history (very slow for projects with a lot of history, tags and branches). So to copy over my SVN info:To speed this process up, I created a shell script:
In order to create such a backup from an existing git SVN repo:
There are two ways to improve your command
git clone --mirror git@myhost:mybackup.git
The one I found is this one, knowing that your command created a mybackup.git directory :There, you have a full working directory.
Alternatively as you can read on this page : https://git.wiki.kernel.org/index.php/Git_FAQ#How_do_I_clone_a_repository_with_all_remotely_tracked_branches.3F
I think both are equivalent up to the last line, and probably the command
git config --bool core.bare false
is cleaner than doing agit init
.It all sums up to the fact that --mirror creates a bare repository and not a working repository, so you need to transform it into a working repository.