Keep in sync your Git repos on GitHub, GitLab & Bitbucket without efforts
Once Install some CLI tools
brew install hub
gem install gitlab
pip install bitbucket-cli
Note: be sure to have tokens as env var, see the beginning of this post for details.
(Also, configure a git alias that will do pull --all
if you want to pull all
remote by default.)
- Export your username (assuming you have the same on all platforms)
export GIT_USER_NAME=$USER
- For new repo (if your repo already exist on GitHub, go to step below.)
export GIT_REPO_NAME=your-repo
mkdir $GIT_REPO_NAME && cd $GIT_REPO_NAME
git init
hub create
- For existing GitHub repo
export GIT_REPO_NAME=$(basename $(pwd))
gitlab create_project $GIT_REPO_NAME "{visibility_level: 20}"
bb create --protocol=ssh --scm=git --public $GIT_REPO_NAME
Then, to add remotes
git remote set-url origin --add https://gitlab.com/${GIT_USER_NAME}/${GIT_REPO_NAME}.git
git remote set-url origin --add https://bitbucket.org/${GIT_USER_NAME}/${GIT_REPO_NAME}.git
git remote add origin-gitlab https://gitlab.com/${GIT_USER_NAME}/${GIT_REPO_NAME}.git
git remote add origin-bitbucket https://bitbucket.org/${GIT_USER_NAME}/${GIT_REPO_NAME}.git
- Check that everything is ok
git remote -v
You should get something like
origin ssh://[email protected]/YOU/YOUR-REPO.git (fetch)
origin ssh://[email protected]/YOU/YOUR-REPO.git (push)
origin ssh://[email protected]/YOU/YOUR-REPO.git (push)
origin ssh://[email protected]/YOU/YOUR-REPO.git (push)
origin-bitbucket ssh://[email protected]/YOU/YOUR-REPO.git (push)
origin-bitbucket ssh://[email protected]/YOU/YOUR-REPO.git (fetch)
origin-gitlab ssh://[email protected]/YOU/YOUR-REPO.git (fetch)
origin-gitlab ssh://[email protected]/YOU/YOUR-REPO.git (push)
😇 Now you can just git push
and git pull --all
!
You can add some nices badges to show the redundancy on your project README
[](https://github.com/YOU/YOUR-REPO)
[](https://gitlab.com/YOU/YOUR-REPO)
[](https://bitbucket.org/YOU/YOUR-REPO)
Adjust YOU/YOUR-REPO
to your need in the markdown.
It will look like this