gitgit-pull

Git pulling changes between two local repositories


I have two clones of same remote repository. I have made some changes to one local repository, how can I pull these changes to the other local repository without pushing it to the remote?


Solution

  • You can treat the second clone the same way you treat a remote respository on another system. You can perform all of the same operations, e.g.

    ~/repo1 $ git remote add repo2 ~/repo2
    ~/repo1 $ git fetch repo2
    

    You'd then have all your second clone's commits in your main clone, labeled with repo2/ (just like your remote branches are probably labeled with origin/ or remote/).

    If you then wanted to merge a remote branch's changes into your current local branch, you could then, e.g.:

    ~/repo1 $ git merge repo2/foo