Can I clone a remote git repository but reference a local repository for efficiency?

StackOverflow https://stackoverflow.com/questions/23531270

  •  17-07-2023
  •  | 
  •  

質問

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
役に立ちましたか?

解決

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
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top