Pushing all git refs from one remote to another
Let’s say you have a project that you want to migrate from an old gitlab instance to a new one. First, create a new project in your new instance, and then
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
git clone git@my-old-gitlab.com:myproject
cd myproject
git remote add new-origin git@my-new-gitlab.com:myproject
# Use git remove -v if you want to see all your configured remotes
# First, we need to delete the symbolic-ref called HEAD, since it's forbidden to push it to a remote repo. We'll add it afterwards
git symbolic-ref --delete refs/remotes/origin/HEAD
# Push all refs (tags also) from origin to new-origin
git push new-origin --tags "refs/remotes/origin/*:refs/heads/*"
# Remove the (now)old origin and rename the new one
git remote remove origin
git remote rename new-origin origin
git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/master
This post is licensed under CC BY 4.0 by the author.