-1

We have 6 sites (one prod, 5 dev) and although they are used for different purposes, they are for the most part the same site, they all use code from the same URL in an SVN repository.

I have imported the SVN repository for the project, including the log, for the project into Git, following the advice here, using a git svn clone command that looks something like this:

git svn clone http://my-project.googlecode.com/svn/ \
      --authors-file=users.txt --no-metadata --prefix "" -s my_project

Now I would like to make those SVN working copies into Git working trees. Meaning, I would like to be able to do Git pushes on the files to the new repository location in Git, but I would rather not move the files for the entire site. Also, there are some local changes in the development sites that I want to keep. I have not seen any good answers that tell how to do this.

For each site, I could do a git clone, copy the svn working copy over the git clone, then move the site code somewhere, and move the git clone with copied site code to where the code for the site was. This seems problematic. Is there any easier way?

Just noticed that the most upvoted answer (not the accepted one) here works. I left off the last command, as it overwrites local changes.

git init     
git remote add origin PATH/TO/REPO     
git fetch 
dougd_in_nc
  • 371
  • 5
  • 20

1 Answers1

1

The .git directory contains a complete Git repository. Clone the repository, and copy its .git directory into each working tree.

You can save a little time and space by doing a bare clone, git clone --bare. This is the contents of the .git directory with no working tree. You can clone that straight into a .git directory in each working tree.

cd working_tree
git clone --bare <url> .git/
Schwern
  • 153,029
  • 25
  • 195
  • 336
  • @dougd_in_nc Did you check what changed? Could it be just permissions? Could you have checked out the wrong branch? – Schwern Dec 30 '21 at 20:17
  • Deleted previous comments... Doing a bare clone didn't work, I got "fatal: This operation must be run in a work tree," however, cloning to another dir and copying the .git dir into svn working dir worked. I had to make sure that all text/source files were not user executable in Git repository as well in working tree so that i would't get a status of modified. – dougd_in_nc Dec 30 '21 at 20:37
  • @dougd_in_nc Not sure why the bare clone didn't work, but I'm glad you got it working. And you've fixed a permissions problem in your repo. – Schwern Dec 30 '21 at 20:39
  • According to the docs I've seen a bare clone isn't attached to a working tree and will not automatically attach itself to files in the directory. – dougd_in_nc Dec 30 '21 at 20:44
  • @dougd_in_nc Git will try to use whatever is in .git/ as its local repository. A bare clone is what is normally in .git/. If you copy a bare clone into some_dir/.git/ then some_dir/ becomes the working tree. There's nothing special in .git/, this is all done by `git` itself. – Schwern Dec 30 '21 at 23:25
  • @dougd_in_nc Alternatively, you tell `git` where to find the .git dir with --git-dir or GIT_DIR. You can also tell it where the work tree is with --work-tree or GIT_WORK_TREE. – Schwern Dec 30 '21 at 23:32
  • 1
    I can verify that some_dir does not become the working tree with a bare clone and instead results in the "fatal: This operation must be run in a work tree" error. Haven't successfully tried the other options but copying from an existing clone does not require extra configuration. – dougd_in_nc Dec 31 '21 at 02:56
  • FYI A colleague pointed out another solution. I added a description and a link to it in my question. – dougd_in_nc Jan 05 '22 at 17:30
  • @dougd_in_nc Yes, that works fine if you're ok with downloading the repo multiple times. A `git clone` is essentially that plus a `git checkout`. – Schwern Jan 05 '22 at 17:40