How-To
Check your remote repository info. In this example I have a project pushed to Github
1$ git remote -v show2origin https://github.com/GandhiNN/iot-vernemq-ktig-stack.git (fetch)3origin https://github.com/GandhiNN/iot-vernemq-ktig-stack.git (push)If you check your git configuration (
PROJECT_NAME/.git/config
), you will see:1[core]2 repositoryformatversion = 03 filemode = true4 bare = false5 logallrefupdates = true6[remote "origin"]7 url = https://github.com/GandhiNN/iot-vernemq-ktig-stack.git8 fetch = +refs/heads/*:refs/remotes/origin/*9[branch "dev"]10 remote = origin11 merge = refs/heads/dev12[http]13 sslverify = falseSuppose that you want to add a remote git repository on your Bitbucket project.
1$ git remote set-url origin --add https://<bitbucket_url>/scm/<bitbucket_project_name>/iot-vernemq-kafka-poc-stack.gitTo be able to do controlled Git workflow (e.g. just pull from Github remote or just push to Bitbucket remote), we add remote repository information using
git remote
.1$ git remote add bitbucket https://<bitbucket_url>/scm/<bitbucket_project_name>/iot-vernemq-kafka-poc-stack.git23$ git remote add github https://github.com/GandhiNN/iot-vernemq-ktig-stack.gitNow our project’s Git configuration contains the information of the new repositories just added.
1[core]2 repositoryformatversion = 03 filemode = true4 bare = false5 logallrefupdates = true6[remote "origin"]7 url = https://github.com/GandhiNN/iot-vernemq-ktig-stack.git8 fetch = +refs/heads/*:refs/remotes/origin/*9 url = https://<bitbucket_url>/scm/<bitbucket_project_name>/iot-vernemq-kafka-poc-stack.git10[branch "dev"]11 remote = origin12 merge = refs/heads/dev13[http]14 sslverify = false15[remote "bitbucket"]16 url = https://<bitbucket_url>/scm/<bitbucket_project_name>/iot-vernemq-kafka-poc-stack.git17 fetch = +refs/heads/*:refs/remotes/bitbucket/*18[remote "github"]19 url = https://github.com/GandhiNN/iot-vernemq-ktig-stack.git20 fetch = +refs/heads/*:refs/remotes/github/*In the sequence of “origin” block, Github remote takes precedence over the Bitbucket one; If you run
git pull
, it will still pull from only Github. If you want to make Bitbucket as the first source, you can just rearrange the sequence of “url.”1$ git remote -v2bitbucket https://<bitbucket_url>/scm/<bitbucket_project_name>/iot-vernemq-kafka-poc-stack.git (fetch)3bitbucket https://<bitbucket_url>/scm/<bitbucket_project_name>/iot-vernemq-kafka-poc-stack.git (push)4github https://github.com/GandhiNN/iot-vernemq-ktig-stack.git (fetch)5github https://github.com/GandhiNN/iot-vernemq-ktig-stack.git (push)6origin https://github.com/GandhiNN/iot-vernemq-ktig-stack.git (fetch)7origin https://github.com/GandhiNN/iot-vernemq-ktig-stack.git (push)8origin https://<bitbucket_url>/scm/<bitbucket_project_name>/iot-vernemq-kafka-poc-stack.git (push)If you want to push your updates to the Bitbucket remote, you can run
git push -u bitbucket <branch_name>
1$ git push -u bitbucket master2Username for 'https://<bitbucket_url>': <bitbucket_username>3Password for 'https://<bitbucket_username>@<domain>@<bitbucket_url>':4Enumerating objects: 32, done.5Counting objects: 100% (32/32), done.6Delta compression using up to 8 threads7Compressing objects: 100% (26/26), done.8Writing objects: 100% (32/32), 12.85 KiB | 4.28 MiB/s, done.9Total 32 (delta 1), reused 0 (delta 0)You can do the same with your Github target.
1$ git push -u github master2Username for 'https://github.com': GandhiNN3Password for 'https://GandhiNN@github.com':4Enumerating objects: 32, done.5Counting objects: 100% (32/32), done.6Delta compression using up to 8 threads7Compressing objects: 100% (26/26), done.8Writing objects: 100% (32/32), 12.85 KiB | 4.28 MiB/s, done.9Total 32 (delta 1), reused 0 (delta 0)10remote: Resolving deltas: 100% (1/1), done.Let’s say that you want to set Bitbucket as the default remote for your git push / git pull activities, you need to add the Bitbucket URL as the remote “origin”
1$ git remote add origin https://<bitbucket_url>/scm/<bitbucket_project_name>/iot-vernemq-kafka-poc-stack.git1$ git remote -v2bitbucket https://<bitbucket_url>/scm/<bitbucket_project_name>/iot-vernemq-kafka-poc-stack.git (fetch)3bitbucket https://<bitbucket_url>/scm/<bitbucket_project_name>/iot-vernemq-kafka-poc-stack.git (push)4github https://github.com/GandhiNN/iot-vernemq-ktig-stack.git (fetch)5github https://github.com/GandhiNN/iot-vernemq-ktig-stack.git (push)6origin https://<bitbucket_url>/scm/<bitbucket_project_name>/iot-vernemq-kafka-poc-stack.git (fetch)7origin https://<bitbucket_url>/scm/<bitbucket_project_name>/iot-vernemq-kafka-poc-stack.git (push)
Notes
To skip SSL verification in your git workflow on your project you can use:
1$ git config --local http.sslverify falseTo save credentials used by your git workflow on your project you can use:
1$ git config --local credential.helper store