遷移一個或多個完整的git倉庫

遷移倉庫:包括所有分支,tag等…

一、遷移一個Git倉庫
把一個git倉庫遷移到另外一個git倉庫,含所有的分支,標籤,歷史記錄,日誌

git clone --mirror <URL to my OLD repo location>
cd <New directory where your OLD repo was cloned>
git remote set-url origin <URL to my NEW repo location>
git push -f origin

二、批量遷移倉庫
move.sh文件

#!/bin/bash

filename=$1
IFS=$'\n\n'

for line in `cat $filename`
do
  # echo $line
  OLD_IFS="$IFS"
  IFS=";"
  array=($line)
  IFS="$OLD_IFS"

  old_origin=${array[0]}
  new_origin=${array[1]}
  echo "old origin: ${old_origin}"
  echo "new origin: ${new_origin}"
  mkdir workdir
  sup_path=`pwd`
  cd workdir
  path=`pwd`
  echo "開始clone項目..."
  git clone --mirror $old_origin
  echo "clone項目完畢."

  for dir in `ls .`
  do
  if [ -d $dir ]
  then
  echo "項目目錄: $dir"
  cd $dir
  echo "修改項目origin url..."
  git remote set-url origin $new_origin
  echo "開始推送新倉庫..."
  git push -f origin
  echo "推送完畢."
  fi
  done
  rm -rf $path
  cd $sup_path
  echo "done"
done

data.txt文件
.txt文件裏面:每一行是一條記錄
舊的git倉庫地址,分號,新的倉庫地址

<舊的git倉庫地址>;<新的git倉庫地址>
<舊的git倉庫地址>;<新的git倉庫地址>
<舊的git倉庫地址>;<新的git倉庫地址>

執行命令

bash move.sh data.txt
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章