0

I have a git bare repository as a remote on a server with 2 network interfaces, whose IP address are 192.168.x.x and 223.x.x.x respectively. I have a signle git project on this single remote origin. Inside the lab this remote can only be accessed via 192.168.x.x (CISCO hairpin disabled), and vice versa (which of course).

Can this remote origin be accessed via like one "git push" or one "git pull" regardless of what network my laptop is on?

On my laptop I tried,

git remote add origin ssh://gogma@223.x.x.x/home/gogma/git/prj.git
git remote set-url --add origin ssh://gogma@192.168.x.x/home/gogma/git/prj.git

didn't seem to work. no issues with ssh itself.

This is what I have:

$ git remote -v
origin  ssh://gogma@223.x.x.x/home/gogma/git/prj.git (fetch)
origin  ssh://gogma@223.x.x.x/home/gogma/git/prj.git (push)
origin  ssh://gogma@192.168.x.x/home/gogma/git/prj.git (push)
$ 
gogma
  • 1
  • 1
  • Did you copy the ssh public key from the laptop to the remote server? `ssh-copy-id -i /path/to/ssh/public/key gogma@192.168.x.x` – ElpieKay Jun 21 '22 at 07:25
  • I'd rather either set up a fake host name (perhaps via ssh config file, or perhaps via local name resolver tricks) so that `origin` maps to `ssh:///path` and `` gets filled in with the right stuff dynamically or based on ssh config (updated when moving around), or create two remote names. The latter is a little klunky because there's actually only one single remote machine, it's just that its network address depends on where you are. – torek Jun 21 '22 at 18:54
  • Note that the resolver trick doesn't depend on Git *or* ssh at all. You just have a name that, dynamically, means "the machine I need to get to, using the address I need to use based on where I am". So it's the best method overall, by far. – torek Jun 21 '22 at 18:55
  • @ElpieKay Yes, I copied to .ssh/authorized_keys and it logs in okay without a passphrase. – gogma Jun 23 '22 at 23:31

1 Answers1

0

That would fail on one, and succeed on the other origin psuhURL entry entry on every git push/pull/clone.

I would rather clone it twice:

  • once in a folder where origin is set to ssh://gogma@223.x.x.x/home/gogma/git/prj.git
  • once in a folder where origin is set to ssh://gogma@192.168.x.x/home/gogma/git/prj.git

Depending on the network, my .bashrc would symlink the right folder to a common path.

ln -s /path/to/network1/project /path/to/project
ln -s /path/to/network2/project /path/to/project

Each one has a otherNetwork remote entry in order for you to do a git fetch otherNetwork when switching /path/to/project, getting the latest commits you did from one folder into the other.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250