Sync git repos between different Git git hosters

Posted in development on March 22, 2018 by Adrian Wyssmann ‐ 2 min read

Github or Gitlab are cool and you can find really nice projects.But in a company environment you may not necessarily use Github or Gitlab, especially if you want to host your code internally - even so they support on-premise installations as well. So in certain cases you may want to “synchronize” between different hosters e.g. Bitbucket (internally) and Github (Internet).

As it is best practice you best fork the required repo into your own space or your enterprise space. Then follow the steps described in http://stackoverflow.com/questions/8137997/forking-from-github-to-bitbucket.

Go to internal git e.g. Bitbucket and create a new repository (its better to have an empty repo)

[adrian@bitbucket ~]$ git clone [email protected]/scm/testproject/myforkedrepo.git
[adrian@bitbucket ~]$ cd myforkedrepo

Now add Github repo as a new remote in Bitbucket called “sync”

[adrian@bitbucket ~]$ git remote add sync [email protected]:def/originalrepo.git

Verify what are the remotes currently being setup for “myforkedrepo”. This following command should show “fetch” and “push” for two remotes i.e. “origin” and “sync”

[adrian@bitbucket ~]$ git remote -v

Now do a pull from the “master” branch in the “sync” remote

[adrian@bitbucket ~]$ git pull sync master

Setup a local branch called “github"track the “sync” remote’s “master” branch

[adrian@bitbucket ~]$ git push -u origin master

Now push the local “master” branch to the “origin” remote in Bitbucket.

[adrian@bitbucket ~]$ git push -u origin master