簡體   English   中英

Git 將倉庫鏡像到特定分支

[英]Git mirror a repo to specific branch

我們公司嘗試將一個 github 項目 fork 到我們自己的 git 服務器,然后我們可以在上面添加我們自己的功能。 我們只想簽出一個特定的分支,並將所有分支和標簽保留到這個分支,然后復制(鏡像?)到我們的 git 服務器。

在您的服務器上創建存儲庫。 在其他地方(不在服務器倉庫中),只克隆分支

git clone --single-branch --branch branch_name github_repo_url

告訴 git你的倉庫在哪里:

git remote 添加我的your_repo_url

然后,使用以下命令將分支推送到您的倉庫:

git push -u 我的; git push --tags -u 我的

“mine” 是你的 repo 的簡寫名稱,它可以是任何字符串,替換默認的“origin”。

這將收集導致branch_name的整個歷史,但沒有非祖先的提交。

留在您本地的原始存儲庫中並將新存儲庫添加為您的遠程存儲庫

git remote add newRemote NewRepoUrl

然后留在你想要推送的特定分支上。 然后將代碼推送到新遙控器中的新倉庫

git push newRemote current_branch_name

注意: newRemote是我放置新 repo url 的遠程名稱

  1. 將舊分支克隆到本地
git clone --bare git_url --single-branch --branch  old_branch_name local_dir
  1. 更改目錄
cd local_dir
  1. 添加新遙控器
git remote add  new_origin new_git_url 
  1. 推送到新的遙控器
git push new_origin  old_branch_name 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM