Setup multiple Git push url in single repo

Kingyinma
1 min readJul 12, 2020

Recently I wanna try more github feature rather than bitbucket as my existing repo is using bitbucket, so i want to find a way to add url from my existing git folder and push to there without clone and copy and paste to there. After I google and I find it is possible, so i write down for who also have this need.

Open terminal of your mac, and cd to your existing repo folder

cd your_repo_folder# here is my example
cd src/test-api

Check your existing remote url

git remote -v

and it should show below, since i am using bitbucket, so it shows bitbucket url

origin https://{username}@bitbucket.org/{workspace}/{repo}.git (fetch)origin https://{username}@bitbucket.org/{workspace}/{repo}.git (push)# here is my example
origin https://kingyinma@bitbucket.org/kingyinma/test-api.git (fetch)
origin https://kingyinma@bitbucket.org/kingyinma/test-api.git (push)

Next, I want to add my github url

git remote set-url --add --push origin https://{username}@{git_host_url}/{workspace}/{git_url}e.g.git remote set-url --add --push origin https://mickyma@github.com/mickyma/test-api.git

The tricky point is I find when i execute above command, i overwrite my existing bitbucket url, so i need to add back my bitbucket url once

git remote set-url --add --push origin https://kingyinma@bitbucket.org/kingyinma/test-api.git

Finally, check remote url again by using

git remote -v

It shows

origin https://kingyinma@bitbucket.org/kingyinma/test-api.git (fetch)origin https://kingyinma@bitbucket.org/kingyinma/test-api.git (push)
origin https://mickyma@github.com/mickyma/test-api.git(push)

Done!

--

--