Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pulling changes between two local repositories

Tags:

git

git-pull

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?

like image 322
Sirish Avatar asked Apr 25 '11 05:04

Sirish


People also ask

When you run git fetch from your local repo it will update your local changes in working area True or false?

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.

How do I pull a commit from another repo?

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.

Should I use git pull or fetch?

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.

How do I pull from another git?

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.


2 Answers

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 
like image 97
djs Avatar answered Oct 06 '22 13:10

djs


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

like image 29
Pedro Moisés Camacho Ureña Avatar answered Oct 06 '22 14:10

Pedro Moisés Camacho Ureña