References:

ITER git repository: https://git.iter.org/projects/IMEX/repos/gittest/browse
ACH gitlab repository: https://gitlab.eufus.psnc.pl/ach/gittest

1. Step by step instructions:

  1. Create or select origin repository, in this case it was ITER git repository
  2. Clone origin repository with --mirror flag:

    git clone --mirror ssh://git@git.iter.org/imex/gittest.git
  3. Change directory to newly cloned mirror repository:

    cd gittest.git
  4. Push mirrored repository to new origin with --mirror  flag:

    git push --mirror git@gitlab.eufus.psnc.pl:ach/gittest.git

    Warning!

    Don’t use git push --mirror in repositories that weren’t cloned by --mirror as well. It’ll overwrite the remote repository with your local references (and your local branches).

  5. Clone newly pushed repository and change directory to it:

    cd ..git clone git@gitlab.eufus.psnc.pl:ach/gittest.gitcd gittest
  6. Check current remote repository:

    git remote -v

    It shall print:

    origin    git@gitlab.eufus.psnc.pl:ach/gittest.git (fetch)
    origin    git@gitlab.eufus.psnc.pl:ach/gittest.git (push)

  7. Rename current default remote repository label to more relevant name:

    git remote rename origin gitlab

    And check the result:

    git remote -v

    It shall print:

    gitlab    git@gitlab.eufus.psnc.pl:ach/gittest.git (fetch)
    gitlab    git@gitlab.eufus.psnc.pl:ach/gittest.git (push)

  8. Add second remote (ITER, original one):

    git remote add iter ssh://git@git.iter.org/imex/gittest.git

    And check results:

    git remote -v

    It shall print:

    gitlab    git@gitlab.eufus.psnc.pl:ach/gittest.git (fetch)
    gitlab    git@gitlab.eufus.psnc.pl:ach/gittest.git (push)
    iter    ssh://git@git.iter.org/imex/gittest.git (fetch)
    iter    ssh://git@git.iter.org/imex/gittest.git (push)

  9. To push or pull to different remote:
    1. PUSH:
      1. Gitlab:

        git push gitlab <optionally-branch-name}
      2. ITER:

        git push iter <optionally-branch-name>

        Note

        First push to newly added remote should be executed with {--set-upstream} flag, e.g.:

        git push --set-upstream iter master
    2. PULL:
      1. Gitlab:

        git pull gitlab <optionally-branch-name>
      2. ITER:

        git pull iter <optionally-branch-name>
  • No labels