如何使用CLI(Shell脚本)将现有的git-reo从本地服务器转移到gitlab-reo



我在我的服务器上有许多git repos。使用命令行(脚本(我想在https://gitlab.companyname.com,形成现有的本地回购。并在gitLab服务器上推送所有带有标签的分支。

在没有企业账户的情况下可以做到这一点吗?

按filename.sh保存以下文件-开路端子-转到文件保存的目录-键入"sh filename.sh"命令,然后点击回车

在这里,所有来自本地服务器的项目都通过使用这个shell脚本移动到您的GitLab服务器。

# Below is project directory where we are clone all projects
cd /Users/abcd.pqrs/Documents/dev/AllProjects
#Private Tocken
declare projectTocken="YourProjectTockenString"
declare namespaceId=111 #(Your NameSpceId from GitLab)
# Source Repo Array
declare -a source_urls=(
"git@source_Server_IP:/home/git/project_code/projects/project1.git"
"git@source_Server_IP:/home/git/project_code/projects/project2.git"
"git@source_Server_IP:/home/git/project_code/projects/project3.git"
)
# Project Names by using *Source Repo* URL Array
declare -a project_names=(
"project1"
"project2"
"project3"
)
# *Destination Repo* URLs
declare -a target_urls=(
"http://destination_Server_IP/groupName/project1.git"
"http://destination_Server_IP/groupName/project1.git"
"http://destination_Server_IP/groupName/project1.git"
)
## now loop through the above Source URL array
for i in "${!source_urls[@]}"
do
# Clone the project into local directory
echo "Clonning  ${source_urls[$i]}"
git clone "${source_urls[$i]}"
# Go to project folder/directory
cd "${project_names[$i]}"
# Create New Project on Gitlab
curl -H "Content-Type:application/json" http://destination_Server_IP/api/v4/projects?private_token="$projectTocken" -d "{ "name": "${project_names[$i]}", "namespace_id": "$namespaceId" }"
# Set the new server URL for this new directory
git remote set-url origin "${target_urls[$i]}"
for remote in `git branch -r | grep -v /HEAD`; do
echo "Switching to $remote Branch"
#Track all the remote branches into local repo
git checkout --track $remote ;
git status
done
#Push All branches to new server
git push origin --all
# Move back to Mobility directory so that next repo will start with new directory in same folder
cd -
pwd
done

根据要求编辑此脚本。

您可以将gitlab repo添加为服务器中的远程存储。然后你可以使用push-all。

在你拥有的每个回购目录中都有这样的东西:

git add remote gitlab <YOUR NEW REPO URL>
git push gitlab --all

最新更新