迁移多个Git回购的更简单方法?

迁移多个Git回购的更简单方法?,git,shell,Git,Shell,我最近刚刚编写了一个脚本,用于将远程Git服务器备份到本地服务器上。然而,我有大约45个不同的存储库,所以这需要复制和粘贴我的代码45次,并更改每个存储库的repo名称。有没有更简单的方法来完成我想做的事情?(就编辑我的脚本而言)以下是我的代码: sudo rm -rf /home/<user>/<localRepoFolder> git clone --mirror git@<remoteIP:repo> /home/<user>/<loc

我最近刚刚编写了一个脚本,用于将远程Git服务器备份到本地服务器上。然而,我有大约45个不同的存储库,所以这需要复制和粘贴我的代码45次,并更改每个存储库的repo名称。有没有更简单的方法来完成我想做的事情?(就编辑我的脚本而言)以下是我的代码:

sudo rm -rf /home/<user>/<localRepoFolder>
git clone --mirror git@<remoteIP:repo> /home/<user>/<localRepos>/<repo>/$(date +%Y%m%d)
cd /home/<user>/<localRepos>/<repo>/$(date +%Y%m%d)
git remote rm origin
git remote add origin git@<localIP>
git push origin --all
git push --tags
sudo rm-射频/家庭//
git克隆--镜像git@/home///$(日期+%Y%m%d)
cd/home//$(日期+%Y%m%d)
git远程rm源
git远程添加源git@
git推送原点——全部
git推送标签

另外,我应该如何编辑脚本,以便在从本地服务器删除2个最新备份后发生故障时保存它们?处理时间戳的If/else语句?

唯一更快的方法是创建一个bash文件,如下所示:

准备回购协议:

#!/usr/bin/env bash
if [ $# != 0 ]
then
name_repo="$*"
email=<your email>
blih -u $email repository create "$name_repo"
blih -u $email repository getacl "$name_repo"
git clone git@<git address>/$email/$name_repo
else
echo "Enter repository name"
fi
#/usr/bin/env bash
如果[$#!=0]
然后
name_repo=“$*”
电子邮件=
blih-u$电子邮件存储库创建“$name\u repo”
blih-u$电子邮件存储库getacl“$name\u repo”
git克隆git@/$email/$name\u repo
其他的
echo“输入存储库名称”
fi
推手

#!/bin/bash
if [ $# = 0 ]
then
commit_message="default commit message"
else
commit_message=$*
fi
git config user.name "<username>"
git config user.email "<mail / git acount>"
git add --all
git commit -m"$commit_message"
git push
#/bin/bash
如果[$#=0]
然后
提交消息=“默认提交消息”
其他的
提交消息=$*
fi
git config user.name“”
git config user.email“”
git add--all
git commit-m“$commit_message”
git推送
和克隆:

#!/bin/bash
if [ $# == 1 ]
then
git clone git@<git address>/<email>/$1
fi
#/bin/bash
如果[$#==1]
然后
git克隆git@/$1
fi

希望有帮助

循环?变量?可以传递给脚本的参数?这与什么有关系?为什么不将git远程IP存储在一个数组中并在其上循环?您听说过吗