Note: Complicated technique desceibed below is required only if cloned repository is working repository (i.e. non-bare repository you commit in, using separate remotes layout), and not bare (or mirror) repository. If cloned.git is a bare repository it is enough to do git clone --bare
(or git clone --mirror
) to recover original report.git repository (just like e.g. alinrus wrote).
Assuming that you used default configuration and modern Git, which means "separate remotes" layout, you would have remote-tracking branches of report.git in remotes/origin (or remotes/report ) namespace.
To re-create report.git repository you would have to push (or fetch) once from remote-tracking branches to ordinary branches, reverting ordinary fetch refspec (at least for branches: tags are always mirrored). So the refspec for one time push (or fetch) would be something like the following: refs/remotes/origin/*:refs/heads/*
plus refs/tags/*:refs/tags/*
.
Example recovery session
Let s assume that original report.git repository contains two branches: master and next , and no tags (tags are mapped 1-1, so they shouldn t be a problem, anyway):
$ git init --bare report.git
# ...
[report.git] $ git branch -a
* master
next
Let s have cloned/.git repository to be oridinary (non-bare and non-mirror) clone of report.git :
$ git clone user@example.com:report.git cloned
Initialized empty Git repository in /tmp/jnareb/cloned/.git/
# ...
[cloned] $ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/next
[cloned] $ git remote show origin
* remote origin
Fetch URL: user@example.com:report.git
Push URL: user@example.com:report.git
HEAD branch: master
Remote branches:
master tracked
next tracked
Local branch configured for git pull :
master merges with remote master
Local ref configured for git push :
master pushes to master (up to date)
Of course status of your branches, and the number of your local branches might differ for your situation. This is just a simple example.
Now let s remove, or better yet rename (move aside) the original repository report.git , to test our recovery operation
$ mv report.git report-copy.git
Now we recovet the state of report.git that it had on last fetch / pull operation in cloned/.git :
$ git init report.git # push won t create new repository
# move to cloned repository
[cloned] $ git push user@example.com:report.git refs/remotes/origin/*:refs/heads/*
Counting objects: 12, done.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (12/12), 839 bytes, done.
Total 12 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (12/12), done.
warning: updating the current branch
# long warning about pushing into current branch
To user@example.com:report.git
* [new branch] origin/HEAD -> HEAD
* [new branch] origin/master -> master
* [new branch] origin/next -> next
Now you can compare report.git and report-copy.git if there are identical. If report.git was non-bare they might differ, because push would not update working directory (and you would need to do git reset --hard HEAD
or git checkout
in report.git yourself), but it is a bare repository, isn t it?
HTH (hope that helps).