1

I have a computer (let's call it A) where I've been working on a project and I have all the source code there. I created a local Git repository and I've been doing several commits.

Now I got a new computer (lets call it B that I'd like to set as server for that repo, so that I can be working in computer A and I can push code to B.
If I would start from zero, I would create the repo in B, and then do a git clone from A. The problem is that I already have the code in A and there are a lot of commits that I can't lose. I would need to somehow copy all code to B, and then import or merge all the commits I had in A, then I could git clone from A. Does it make any sense?

TimWolla
  • 31,849
  • 8
  • 63
  • 96
  • Cloning the repository from B will work fine, all you have on A will be replicated there. What exactly is what you are worrying about? – vonbrand Mar 17 '14 at 01:31

2 Answers2

0

You can initialize a bare repository and then simply push your current history:

git init --bare # On box B

And then:

git remote add origin <box b>
git push --mirror origin

The man page explains --mirror:

   --mirror
       Instead of naming each ref to push, specifies that all refs under
       refs/ (which includes but is not limited to refs/heads/,
       refs/remotes/, and refs/tags/) be mirrored to the remote
       repository. Newly created local refs will be pushed to the remote
       end, locally updated refs will be force updated on the remote end,
       and deleted refs will be removed from the remote end. This is the
       default if the configuration option remote.<remote>.mirror is set.

See also: Is "git push --mirror" sufficient for backing up my repository?

Community
  • 1
  • 1
TimWolla
  • 31,849
  • 8
  • 63
  • 96
0

You won't lose any of your commits by cloning your project on Computer B. You'd do work on computer A, push the commits, and pull them on Computer B. Perhaps I'm not fully understanding your conundrum, but this seems like the easiest solution.

opticon
  • 3,494
  • 5
  • 37
  • 61