49

I am in the process of creating a Git working copy from our SVN server with 'git svn clone'. But this takes quite some time (we have > 20.000 revs and almost 10.000 files). I have some other machines (for other developers) that I would like to setup the same way. Will it be possible to copy the resulting files from the first machine onto others, so as to spend less time?

In other words, is there anything in a Git working copy that ties it to the machine it was created on?

Thanks.

Xavier Nodet
  • 5,033
  • 2
  • 37
  • 48
  • 6
    Yes you can, but there's no need to copy the full working tree. You can copy just the `.git` folder without the working tree (i.e. as a "bare" repo) and then checkout the latest working tree on the other machine. – Ben James Jan 11 '10 at 14:51

5 Answers5

57

You can copy it, everything is inside the .git folder and is not dependant on anything else.

Arkaitz Jimenez
  • 22,500
  • 11
  • 75
  • 105
  • 11
    Almost true. Aside from configuration items like custom diff drivers and hook scripts that might reference external programs, there are some simple configuration items that usually vary across platforms. When copying between different platforms one should check/set/unset items like core.ignorecase, core.autocrlf, core.safecrlf, core.fileMode (and probably some others). I think it should always be safe to re-clone from a copied .git directory though. – Chris Johnsen Jan 12 '10 at 07:14
  • just cloned my whole dev-environment with 4 repos in it by simply copying it a few times and making each its own branch. worked flawlessly. – Chris Jul 11 '18 at 08:41
11

It's also worth mentioning that if you have no local changes ("git status" doesn't show anything you want to keep), you can copy only the .git directory and do a "git checkout ." from the (almost-empty) repository root directory at the end.

If it's a slow link it may also be worth repacking the repository before the transfer.

The only thing I worry a little bit about is if git-svn remembers some user information that you don't want to copy to the other developers.

Cypherpunks
  • 111
  • 2
  • 1
    My name and email address indeed appears in .git/logs/refs/remotes/trunk. Although the directory is named 'logs', I wonder if this could be an issue for another developer... – Xavier Nodet Jan 12 '10 at 08:42
3

Nope, it'll be fine to just copy the repo's root directory. Just make sure you get any invisible files, too, especially the .git directory (in the project's root) which contains all the config information for the repo.

mipadi
  • 398,885
  • 90
  • 523
  • 479
0

If you use the worktrees feature, it will break because the feature uses absolute paths. yourworktreefolder/.git points to parentgitabsolutepath/.git/worktrees/yourworktreename

But it's easy to fix, just update the path in yourworktreefolder/.git to point to the new parent path.

Pascalius
  • 14,024
  • 4
  • 40
  • 38
0

Just attempted this same strategy in pretty similar SVN --> Git migration scenario, but I encountered a "dubious ownership error".

The strategy we used was I git SVN cloned the repo to import the revision history, had everyone pull an update in SVN, and did a final git svn fetch/rebase to get the git repo synced with SVN one last time. Then, I zipped the .git folder from my local repository and emailed it to all team members. This way when the .git folder was placed in the root of the project directory, the remotes and upstream branches would be pre-configured, we would not have to go through the trouble of configuring and setting up a new project from scratch as the project is old and it takes alot to get a new project actually running, and it would (theoretically) recognize only the pending changes each person had thus eliminating the need for us to have clear working directories.

However when we unzipped the folder into the project, it refused to recognize as a git repo because the repository was linked to me and my computer, stating "Fatal: dubious ownership error"

The only ways around this I can think of is either

  1. To have each person clone the entire repo from Github, then copy the .git folder from the cloned directory into the deployed project, as that .git folder would be assigned to each user.

  2. run the command git config --global --add safe.directory <absolute path to project directory> on each person's computer, but I have read that this can be buggy.