Accessing a Git Repository through multiple Remotes

To access an internally hosted Git repository (in this example hosted with GitBlit) from remote one option is to create a tunnel with OpenSSH.

$ ssh -L localhost:12345:gitblit.server:12345 -i ~/.ssh/tunnel_rsa tunnel@remote-gateway

A convenient way is to store the Git credentials in .ssh/config in your local user’s home directory:

Host gitblit_tunnel
  Hostname localhost
  Port 12345
  User fluffi
  IdentityFile ~/.ssh/gitblit_rsa

With the tunnel established all you need to do is to add a second remote to your local working copy:

$ git remote add gitblit_tunnel ssh://gitblit_tunnel/repositories/My-Project.git

Verify the new configuration - list all Git remote repositories:

$ git remote -v
gitblit_tunnel  ssh://gitblit_tunnel/repositories/My-Project.git (fetch)
gitblit_tunnel  ssh://gitblit_tunnel/repositories/My-Project.git (push)
origin  ssh://gitblit.server:12345/meadows/repositories/My-Project.git (fetch)
origin  ssh://gitblit.server:12345/meadows/repositories/My-Project.git (push)

Git it done ;-)

Show Comments