Skip to content

Migrate all branches and tags to bitbucket/github/gitlab/other remote endpoint

To have a real world scenario think about the task to migrate from an existing private gitweb repository to bitbucket, with all tags and branches.

The solution simple und just needs some time if the repository is a bigger one.

First, you have to create an empty and new repository at bitbucket.

cd <path you want to do this action>
#the next step is just for safety reasons
mkdir <repository_name>
git clone --mirror git@<your host>:<repository_name>.git .
git push --mirror git@bitbucket.org:<user_name>/<repository_name>

See how easy it is? Why not write a simple bash script?

#!/bin/bash
####
# @link https://artodeto.bazzline.net/archives/19519-Migrate-all-branches-and-tags-to-bitbucketgithubgitlabother-remote-endpoint.html
# @since 2017-11-06
# @author stev leibelt <artodeto@bazzline.net>
####

if [[ $# -lt 2 ]];
then
    echo ":: Invalid arguments provided."
    echo "   <command> \"<source repository url>\" \"<destination repository url>\""

    exit 1;
fi

DESTINATION_REPOSITORY_PATH="${2}"
SOURCE_REPOSITORY_PATH="${1}"
TEMPORARY_DIRECTORY="migrate_git_branch"

echo ":: Creating temporary directory."
mkdir "${TEMPORARY_DIRECTORY}"

cd "${TEMPORARY_DIRECTORY}"

echo ":: Cloning from source repository.".
git clone --mirror "${SOURCE_REPOSITORY_PATH}" .

echo ":: Pushing to destination repository."
git push --mirror "${DESTINATION_REPOSITORY_PATH}"

echo ":: You have to remove the following temporary directory if you want to."
echo "   "$(pwd)

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

The author does not allow comments to this entry

Add Comment

E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
To leave a comment you must approve it via e-mail, which will be sent to your address after submission.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Markdown format allowed
Form options