86

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.

Devvyn
  • 87
  • 7
jeffreyveon
  • 13,400
  • 18
  • 79
  • 129
  • 4
    not really a local repository if it's on another computer, in my opinion: thus @Antoine's [answer](http://stackoverflow.com/a/4131211/155090) better matches your question's title … – RubyTuesdayDONO Feb 04 '14 at 10:00
  • … while @Amber's [answer](http://stackoverflow.com/a/4131239/155090) matches the clarifying details of your question's narrative. – RubyTuesdayDONO Feb 04 '14 at 10:00
  • 1
    I wish this question had a Windows answer – Brandon Aug 12 '16 at 14:09

7 Answers7

121

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

Amber
  • 507,862
  • 82
  • 626
  • 550
37

Have a look at git pull --help

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

Antoine Pelisse
  • 12,871
  • 4
  • 34
  • 34
  • 7
    Specifically, under the section *GIT URLS*, it says: "For local repositories, also supported by git natively, the following syntaxes may be used: `/path/to/repo.git/`, `file:///path/to/repo.git/`" – jemmons May 06 '13 at 15:42
14

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
Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539
8

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.

Benoit Courtine
  • 7,014
  • 31
  • 42
4

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.

Alex
  • 948
  • 1
  • 13
  • 17
  • You can of course have multiple remotes. So on host A, I would configure two remotes: one called origin which is where you cloned from, and one called B which is the repo on host B – Martin Bonner supports Monica Dec 19 '18 at 10:03
  • @MartinBonner I know you can which is clearly stated in the accepted answer. I'm merely stating that you do not have to. Looks like the accepted answer was updated to state the same since. – Alex Dec 19 '18 at 10:10
  • 1
    I find this actually incredibly useful – Bart van Kuik Mar 17 '20 at 12:17
2

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
Sagar P. Ghagare
  • 542
  • 2
  • 12
  • 25
McQuade
  • 131
  • 1
  • 4
0

I've come up with

git clone /path/to/local/repository
Vlad T.
  • 2,568
  • 3
  • 26
  • 40