When using Git for version control, many people use GitHub as a place to hold remote repositories and push their repositories there. I recently started using BitBucket also and wanted to be able to simultaneously update my GitHub and BitBucket repositories when changes were made.
To begin, rename your current remote (most likely named origin) to a different name. I’d rename this to the name of the service you are using, such as Github or bitbucket.
git remote rename origin github
You can then add the remote for your second remote repository, in this case, a BitBucket repository.
git remote add bitbucket email@example.com:username/example.git
Afterward, you’ll want to set up your origin remote to push to both of these. Issue the following command:
git config -e
You will be greeted with your Git configuration (most likely using vim). Add the
[remote "origin"] section to the bottom of the file with the URLs from each remote repository you’d like to push to.
[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true precomposeunicode = false [branch "master"] remote = github merge = refs/heads/master [remote "github"] url = firstname.lastname@example.org:username/repo.git fetch = +refs/heads/*:refs/remotes/github/* [remote "bitbucket"] url = email@example.com:username/repo.git fetch = +refs/heads/*:refs/remotes/bitbucket/* [remote "origin"] url = firstname.lastname@example.org:username/repo.git url = email@example.com:username/repo.git
You can then push to both repositories by issuing:
git push origin master
Or to a single one by issuing either of these commands:
git push github master git push bitbucket master