When at home, git fetch origin master
should connect over ssh to git@192.168.xx.xx
.
When on the road, git fetch origin master
should connect over ssh to git@xxx.linkpc.net
.
/etc/hosts
entries to delegate ips is a nice solution but includes sudoing and entering the root password which is kind of tedious. origin
is called will delegate the correct ip, is ideal . How could someone tackle with this issue using a solution that -by all means- shall not be considered "of a hackish character"?
I'm going to give you a hint and you can formulate the solution. You might be able to use your SSH config with the Match
and exec
keyword :
Match
Restricts the following declarations (up to the next Host or Match keyword) to be used only when the conditions following the Match keyword are satisfied.
...
The exec keyword executes the specified command under the user's shell. If the command returns a zero exit status then the condition is considered true.
Remember that you are tunneling over SSH, so your ~/.ssh/config
brings a per-user hosts file back into the question, eg,
Host dynamic-repo-host
HostName 192.168.xx.xx
#HostName xxx.linkpc.net
Then modify the URL of origin
as in
ssh config remote.origin.url git@dynamic-repo-host
Modifying ~/.ssh/config
by hand as appropriate then gives the effect you want.
If you want a completely hands off solution, look into using Match
in ~/.ssh/config
, but the specific commands to execute will depend on the particulars of the networks on which your local machine runs.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.