Search code examples
gitgit-pullpull

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


Solution

  • 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.