moodseller
moodseller

Reputation: 212

Git pull a repository to local computer from a remote computer

I have setup an ssh connection on computer B and I am connecting to it properly via ssh. I want to execute a git pull command so that it would pull the repo to computer A instead of B. Is that too much of a hassle or maybe is there an alternative?

I basically need to copy whatever git pull pulled on computer B to my computer A. The only thing I have is just an ssh connection between the two and the repo is only reachable from computer B.

Upvotes: 3

Views: 2933

Answers (4)

phd
phd

Reputation: 95101

It's possible to run git commands over double ssh tunnel. The accepted answer there is a bit outdated, ssh currently can construct a tunnel without external commands like netcat or socat.

Configure in your ~/.ssh/config:

Host server
   HostName git-server
   ProxyCommand ssh -W %h:%p B

This configures ssh to start a connection to the host B and opens a tunnel over that connection to the host git-server. Run

git pull ssh://server/path/to/repository

Another possible solution is to use ext:: remote helper. See the second answer at the linked question. Run

git pull "ext::ssh -t B ssh git-server %S '/path/to/repository'"

Upvotes: 1

Kais Ben Daamech
Kais Ben Daamech

Reputation: 122

An other solution,(and the most straightforward solution in my opinion) is to just :

  • Connect to the remote machine via SSH
  • Push the remote changes to a git branch
  • Pull the changes from the remote branch from your local machine

Upvotes: 1

piarston
piarston

Reputation: 1867

If I understand correctly, you want to use Git over an SSH tunnel so that computer A can access the repository REPO.git on computer C via computer B

  1. On computer A, open the SSH tunnel:

    ssh -L3333:compC:22 compB

  2. From a second console on computer A:

    git clone ssh://git@localhost:3333/REPO.git

Upvotes: 3

N_Sys
N_Sys

Reputation: 21

I'm not sure it will answer your question, but if it's only for pulling, you can use the scp command after pulling on B:

scp <source> <destination>

It will copy as the cp command but through your ssh connection.

Upvotes: 1

Related Questions