1

I want to push and syncronize my code in two different remote repository, to Gitlab and Github at the same command, is it possible?

1
  • 2
    Trying to push directly to both gets complicated. If both have active development they can get out of sync with each other and your own repository. Instead I'd recommend declaring one the "active" repository where new work gets done on, and the other a read-only "mirror". Push to the active repository as normal. Set up a new clone of the active repository, one that is guaranteed to be clean of any local commits, and git push --mirror to the mirror periodically.
    – Schwern
    Commented Apr 30, 2019 at 17:33

2 Answers 2

5

Yes. Just define two remotes for your working copy:

git remote add lab https://gitlab.com/...
git remote add hub https://github.com/...

Push takes a repository as a parameter:

git push lab master
git push hub master
3
  • 2
    For a single line git push lab master;git push hub master :) Commented Apr 30, 2019 at 18:00
  • 1
    Or even for repo in $(git remote) ; do git push "$repo" master ; done ...
    – choroba
    Commented Apr 30, 2019 at 18:14
  • If you have more than 2 remotes that could screw you. Altho you should only have permission to push to those 2 remotes. Commented Apr 30, 2019 at 18:18
4

Let's me recommend this push-to-all-remotes alias:

git config [--global] alias.push-to-all-remotes '!git remote | xargs -I% -n1 git push %'

Usage: git push-to-all-remotes master.

Taken from gitalias.com (full disclosure: I'm a contributor there).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.