2

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.

Antonio Rodríguez
  • 976
  • 2
  • 11
  • 25
  • 1
    Have you tried `git fetch --all`/`git fetch origin` before pushing? Maybe `git pull --all`, see https://stackoverflow.com/q/67699/10871900 – dan1st Nov 11 '20 at 08:41

1 Answers1

2

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

Antonio Rodríguez
  • 976
  • 2
  • 11
  • 25
  • I'm still reading through the other answer -- I went through same thing as you, I am wondering if I can bring in the branches from my original repo after the fact, since master in my new repo now has changes not in the original repo. I am thinking I'd not push with --all, for one thing. – learning2learn Apr 13 '21 at 18:46
  • I don't think you can add those old commits if you have newers already pushed. All you can do is create a new branch and push your old commits there. Also, you can make a new repo, add first your old commits and then the new ones. – Antonio Rodríguez Apr 15 '21 at 11:34