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?
You can consider git fetch the 'safe' version of the two commands. It will download the remote content but not update your local repo's working state, leaving your current work intact.
In order to get commits from the other repository, You'll need to add the other repository as a remote, then fetch its changes. From there you see the commit and you can cherry-pick it.
When comparing Git pull vs fetch, Git fetch is a safer alternative because it pulls in all the commits from your remote but doesn't make any changes to your local files. On the other hand, Git pull is faster as you're performing multiple actions in one – a better bang for your buck.
If you just want it to download the changes without automatically merging, use git fetch instead of git pull . Git will now yell at you about not being able to find a repo if you try to push to upstream (and sorry about the Rickroll, but it was the first random string that popped into my head). Excellent, thanks.
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 ~/repo1 $ git merge repo2/foo
To add to djs response. After you add the local repo you can treat it as master, so all the other git commands work as normal.
For example if you have made some changes in directory A and save it in commits. To retrieve those changes in directory B (same computer) you simply open a terminal in that directory and you git pull
git pull
This will copy any changes in directory A. I use this system so that I can have a "development" environment (dir A) and a "production" environment (dir B). I only git pull in dir B
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With