0

I have my local development repo on Windows at C:\Dev\myrepo, that was cloned from the remote repo is at git@githost.com:myrepo.git. I’m getting ready to deploy it and I'd like to clone the repo in a different location, C:\Publish\myrepo so that it's completely clean.

What I'd like to do is:

  1. Clone the remote repo but leverage the existing local repo so that the entire repo doesn't have to be downloaded needlessly.
  2. After the clone is complete, I don’t want there to be any connection between the two local repos.

I've read a few things about --reference and --bare and --share, and it is hard to be certain whether things are going to really do what I expect them to do.

Will the following command do what I want?

cd /c/Publish
git clone --reference /c/Dev/myrepo git@githost.com:myrepo.git
Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
Sean
  • 8,407
  • 3
  • 31
  • 33
  • Have you looked into Capistrano? http://capistranorb.com I am not a Ruby person (yet!) but have used it with great success to handle PHP codebase deployments. – Giacomo1968 May 08 '14 at 01:41
  • @JakeGould How is that related to the question? – hek2mgl May 08 '14 at 01:45
  • @hek2mgl What the original poster is describing, specifically the part that reads “Clone the remote repo but leverage the existing local repo so that the entire repo doesn't have to be downloaded needlessly.” is pretty much 100% what Capistrano does already. The only reason I did not suggest that as an answer is—to my knowledge—Capistrano needs a target server to do the job. Have you used it? It’s pretty great. – Giacomo1968 May 08 '14 at 01:48
  • You have too much fantasy ;) Btw, capistrano is ok but far from great. (imo) A simple shell script can be crafted faster, is more powerful and gains full control over the deploy process. However, this question is not about web application deployment. – hek2mgl May 08 '14 at 01:50
  • `s/gains/allows to gain/` ... – hek2mgl May 08 '14 at 01:56
  • @hek2mgl Let me say again, “The only reason I did not suggest that as an answer is—to my knowledge—Capistrano needs a target server to do the job.” – Giacomo1968 May 08 '14 at 02:03
  • Possibly related: [What are the differences between git clone --shared and --reference?](http://stackoverflow.com/q/23304374/456814). –  May 08 '14 at 05:25

1 Answers1

3

You can follow these steps:

cd '/c/Publish'

# Clone the local repository. origin points now to '/c/Dev/myrepo'
git clone '/c/Dev/myrepo'

# Remove the local origin
git remote rm origin

# Add the remote origin
git remote add origin git@githost.com:myrepo.git

# Assuming the master branch was cloned, 
# you need to set that up to track the remote master
git branch --set-upstream-to=origin/master master

# Tracking for other branches will be set up automatically with a pull
git pull
Sean
  • 8,407
  • 3
  • 31
  • 33
hek2mgl
  • 152,036
  • 28
  • 249
  • 266
  • It could be done this way, true. But what I really want is a pure copy of the code as would be yielded by a clone from the remote repo. The thought of reproducing the .gitignore rules for xcopy gives me a headache. And with all the features that are built in to git, this seems a very fair question. – Sean May 08 '14 at 03:24
  • I don't understand the problem. Why would you "reproduce the .gitignore rules for xcopy"? – hek2mgl May 08 '14 at 03:27
  • Because the code base stored in C:\Dev\myrepo has a bajillion artifacts from compiling, running, etc., that I don't want to interfere with the deploy. – Sean May 08 '14 at 03:30
  • Ok, then use my first suggest. I've rolled back my answer – hek2mgl May 08 '14 at 03:37
  • @hek2mgl - This is exactly what I first thought to do but I thought maybe there was more implied by clone that would have to be undone. Is removing the remote and adding the correct remote really all there is to it? – Sean May 08 '14 at 17:32
  • I don't know a better solution. Also it is quite simple to achieve. – hek2mgl May 08 '14 at 18:01
  • What I ended up doing is a variation of your other answer, @hek2mgl. First, I clone git@githost.com:myrepo.git at C:\dev\myrepo for development. For deployment, I cloned git@githost.com:myrepo.git at C:\publish\pure\myrepo. Then, whenever I want to deploy I just pull at pure\myrepo, copy that to C:\publish\build\myrepo, where I build, deploy, and delete when done. The cycle continues without ever having to clone again. This is different than what's asked in the question, but is worth noting, I think. – Sean May 21 '14 at 18:45