简体   繁体   中英

Git sync repository in two different workspaces(folders) on the same computer

I am working on a git repository in which I don't have remote push(write) permission. I need this repo(in sync: same branch, same code) in two different work spaces(cloned into different folders) on same host. One solution is to do the same change at both the places. But this is just duplication of the effort because it will be exactly same change and ultimately I will be pushing these changes to remote from one repo only.
Hence, I wanted to do the following:

  1. Do the changes in one workspace followed by local-commit
  2. Pull these change into another workspace without pushing these changes into remote .

    How can i do this in git.

Thanks,
Shantanu

There are two ways to do this both are changing the origin of the repo's to point one repo.

Lets assume that your repo is A

once you clone the repo to your local 'first destination', you will have the origin in that repo pointing to your remote, which will be https://github.com..../A.git

Now if you want to clone the repo again to your 'second destination' you can either clone it from the remote or use your local.

  1. if you are choosing remote option: Then go to the repo and update the git remote origin to your local repo.

    git remote set-url origin localpath/A.git

  2. if you are using local options: You don't have to do anything. Just clone properly with the git clone pointing to your local repo. example for windows

    git clone C:\\xxxxxx\\A\\.git

    The above will set the origin to your local repo. So you can go ahead and commit the file in the first cloned location and do a pull from the second cloned location and they will be in sync with each other.

All,

For me the repository must start absolutely empty and the files from the 20+ directories must be added from the 1st non-repository directory, then as the additional directories are read their files must then merge with the newly added files in the repository.

Cheers!

TBNK

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM