How do I pull from another computer's repository in Git?

GitGit Pull

Git Problem Overview


For example, I have cloned the origin repository on two computers. Then, I go ahead and make some changes and commit to the local repository of computer A. How do I now pull these changes to computer B? Both computer A and B are connected to a network.

What I am looking for will be the equivalent of someone manually creating a patch and sending it to me, which I can apply to my working copy/local repo.

Git Solutions


Solution 1 - Git

If the machine you want to pull from is accessible via ssh, you can add the repository on it as a remote via ssh, and then pull from it like you would any remote:

$ git remote add repo_b username@host:path/to/repository.git
$ git pull repo_b master

(You can skip the step of adding a remote and just specify the full URL in the git pull command instead of a remote name, but if you're going to be pulling from the repository on a regular basis, adding it as a remote will save you lots of typing.)

Solution 2 - Git

Have a look at git pull --help

This would give something like git pull /my/other/repository

Solution 3 - Git

You can set up an actual server with git daemon. Otherwise, you can use git bundle, which bundles git's internal representation into a file that can be unbundled with git pull at the other end.

E.g. from the git docs, bundling everything:

git bundle create file.bundle master

Then, on the other end, you can do something like:

git pull file.bundle HEAD

Solution 4 - Git

If you can connect to computer B by ssh, you can use:

git clone user@host:/path/to/repo

It will enable remote tracking through this ssh connection, and allow you to use git pull/push.

Solution 5 - Git

It worked for me for a local repository with another computer:

git remote add origin_username username@10.0.0.2:/home/username/dev/project/main/.git/

git pull origin_username master

or

git pull origin_username some_branch

Solution 6 - Git

A bit too late, but for all it worth and to extend the Antoine Pelisse answer, you can also pull from ssh host that has the same repo with couple of more commits in it, without adding a remote to your config:

git pull user@host:/path/to/repo  # while in the local repo folder

Just to be clear - one of possible uses of this is when you have two hosts (A and B) that cloned the same repo from a remote, and you've committed some changes on host A and do not wish to push them to remote (yet), but instead want to pull those commits from host B. The command above with synchronise your repos without pushing to remote.

Solution 7 - Git

I've come up with

git clone /path/to/local/repository

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjeffreyveonView Question on Stackoverflow
Solution 1 - GitAmberView Answer on Stackoverflow
Solution 2 - GitAntoine PelisseView Answer on Stackoverflow
Solution 3 - GitMatthew FlaschenView Answer on Stackoverflow
Solution 4 - GitBenoit CourtineView Answer on Stackoverflow
Solution 5 - GitMcQuadeView Answer on Stackoverflow
Solution 6 - GitAlexView Answer on Stackoverflow
Solution 7 - GitVlad T.View Answer on Stackoverflow