views:

294

answers:

3

I have two git repositories:

  1. report.git (Master on remote location)
  2. cloned.git (Local)

I lost report.git. I have the cloned.git. I want to clone other repositories from this cloned.git. This is possible but my question is am I missing something? Is cloned.git really the same as the master report.git?

cloned.git still points to the Master report.git. I changed this by removing the options in the .git/config. Is this enough?

+5  A: 

Your cloned.git repository is a clone (copy) of report.git in the state that report.git was when you cloned or last pulled from report.git

Your cloned.git has always been a master, report.git has always been a master as well. It's the beauty of git.

Andrei Serdeliuc
+4  A: 
git clone --bare localrepo.git newremoterepo.git

http://www.kernel.org/pub/software/scm/git/docs/git-clone.html

alinrus
+3  A: 

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 [email protected]: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: [email protected]:report.git
  Push  URL: [email protected]: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 [email protected]: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 [email protected]: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).

Jakub Narębski