开发者

How to prevent "git remote add ssh://" from establishing a connection?

开发者 https://www.devze.com 2023-02-20 22:13 出处:网络
I wrote a backup script for my server\'s users git repos. It adds new remotes开发者_JAVA技巧 to every repos (my own and other users too) pointing to the backup servers.

I wrote a backup script for my server's users git repos. It adds new remotes开发者_JAVA技巧 to every repos (my own and other users too) pointing to the backup servers.

This is a tricky operation since the script runs as root through cron.daily, must add the remote as the user owning the repo and establish the ssh connection as myself since I'm the only one allowed to connect through ssh to the different backup servers.

Everything would work if git wasn't trying to establish an ssh connection when running these commands:

  • some_user$ git remote add REMOTENAME ssh://$me@$server/...
  • some_user$ git config remote.REMOTENAME.mirror true
  • some_user$ git remote set-url REMOTENAME ssh://$me@$server/...
  • some_user$ git remote set-url --push REMOTENAME ssh://$me@$server/...

How can I prevent git from establishing a connection with these commands?

Thanks!


Options that come to mind:

  • Modify the .git/config file yourself instead of through git config and remote commands
  • A modified git compilation that doesn't attempt to connect when you setup your configuration.
  • Use rsync on the .git directory to avoid configuring remotes.

I'd probably try the first bullet point. Diff the .git/config file between its prior state and when you run those four commands and insert into new files as appropriate.


I don't think that any of the commands that you quote should cause an SSH connection to be made. (Indeed, it's often annoying that after adding a new remote that contains a typo in the URL, one doesn't find out until one tries to fetch.)

If you update your questions to include the version of git that you are using, and the error message that you get with each command, people may be able to help more.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号