Import into GitLab a git project including all branches

Viewed 1213

I have a git server in a synology nas. Now I have installed gitlab into a new server where I want to import all my repositories. As far as I know I have to clone every repository from my git server and import them manually one by one. So I started to clone my repositories:

git clone ssh://usuario@servidor/ruta/repositorio.git repositorio

Then I move into repository folder, added a new remote for the new server and pushed:

cd repositorio
git remote rename origin origin-git
git remote add origin ssh://git@gitlab/url/repository.git
git push -u origin --all
git push -u origin --tags

Now I got to my gitlab and I can see my master branch with all its commits. I can also see other commits but my problem is that they are not assigned to any branch.

Here you can see commits graphic generated by gitlab. There should be another branch called desarrollo.

Gitlab commits graphic

If I try to clone this repository from Gitlab I cannot see all those commits since the only existing branch is master.

Edit: adding git fetch --all or git pull --all doesn't make any difference.

1 Answers

Adding git fetch --all or git pull --all didn't work at all. It does not load any other branch than master. You can check it out using git branch to see local branches and git branch -a to see local and remote branches.

The solution was to track all branches, adding some code for that, an run it before renaming origin:

# Track all branches
for branch in $(git branch --all | grep '^\s*remotes' | egrep --invert-match '(:?HEAD|master)$'); do
    git branch --track "${branch##*/}" "$branch"
done
# Pull fetched branches, just in case
git fetch --all
git pull --all

Then rename origin, as usual, and push everything.

git remote rename origin origin-git
git remote add origin ssh://git@gitlab/url/repository.git
git push -u origin --all
git push -u origin --tags

With all this done, you can check gitlab and you'll see al branches synced.

Solution for fetching all branches seen here: How to fetch all Git branches

Related