Make sure that prior take this steps the project has been migrated: Migrate a project
touch ~/.local/bin/migrate-git-repo
chmod +x ~/.local/bin/migrate-git-repo
~/.local/bin/migrate-git-repo
and paste this content:#!/usr/bin/env bash
# Usage: ${0} [OLD_REMOTE] [NEW_REMOTE] [REMOTE_NAME]
OLD_REMOTE="${1:-gitlab.com:coopdevs}"
NEW_REMOTE="${2:-git.coopdevs.org:coopdevs\/migrated-projects}"
REMOTE_NAME="${3:-origin}"
find "${PWD}" -type d -name '.git' | while read dir; do
cd "${dir}/.."
current_remote_url=$(git remote get-url "${REMOTE_NAME}")
if grep "${OLD_REMOTE}" <<< "${current_remote_url}"; then
new_remote_url=$(sed "s/${OLD_REMOTE}/${NEW_REMOTE}/" <<< "${current_remote_url}")
echo "Changing
${current_remote_url} to
${new_remote_url}"
git remote set-url "${REMOTE_NAME}" "${new_remote_url}"
fi
done
You can now call the script by executing migrate-git-repo
anywhere.
This script is recursive: it will perform the changes allong all repos in subfolders. Mind that when executing it.
$ cd coopdevs-email-signature-generator
$ migrate-git-repo
Changing
git@gitlab.com:coopdevs/coopdevs-email-signature-generator.git to
git@git.coopdevs.org:coopdevs/migrated-projects/coopdevs-email-signature-generator.git
The helper script changes the remote url to the migrated-project subgroup. That’s not the final destination of the migrated repo.
Despite this, git
will
(1) still work and
(2) warning and telling us the proper command to finish config:
$ git push
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote:
remote: Project 'coopdevs/migrated-projects/coopdevs-email-signature-generator' was moved to 'coopdevs/tooling/coopdevs-email-signature-generator'.
remote:
remote: Please update your Git remote:
remote:
remote: git remote set-url origin git@git.coopdevs.org:coopdevs/tooling/coopdevs-email-signature-generator.git
remote:
remote:
To git.coopdevs.org:coopdevs/migrated-projects/coopdevs-email-signature-generator.git