Git 如何一次推兩個 Repository

Git 一次推兩個 Repository

前言

有測試機與正式主機,但不想要推測試機再去處理CI/CD等問題,一切簡而言之就是,

local的 git設定兩個 push_url

指令

1
2
git remote set-url --add --push origin git@first_domain:git/repos/project.git
git remote set-url --add --push origin git@second_domain:git/repos/project.git
  • 如果當初已經是從第一台主機 clone下來後,還是一樣要設定兩次,他會將之前的url蓋掉

直接修改 .git/config 設定檔

  • 專案的 git設定檔在 /project/.git/config

fetch = +refs/heads/*:refs/remotes/origin/* 的下面新增兩行push_url

1
2
3
4
5
[remote "origin"]
url = ted@www.tyeydy.com::git/repos/project.git
fetch = +refs/heads/*:refs/remotes/origin/*
pushurl = git@first_domain:git/repos/project.git
pushurl = git@second_domain:git/repos/project.git