自己寫的東西,要同時推送多個git地址,解決辦法如下:
1.先要初始化你的git
進入自己的項目目錄,然后執(zhí)行 git init
cd /app/code/go-study
git init
2.執(zhí)行以下腳本:
#!/bin/bash
#author Oliver
#since 2020-09-03 15:24:31
git remote rm origin
#replace your git location
git remote add origin 'https://github.com/**********'
git pull remote master
git add .
git commit -m $1
git push origin master --force
if [ "$?" = "0" ]
then
echo -e "\033[42;34m push to github success! \033[0m"
else
echo -e "\033[41;30m push to github fail! \033[0m"
exit 1
fi
git remote rm origin
#replace your git location
git remote add origin 'https://gitee.com/**********'
git pull remote master
git add .
git commit -m $1
git push origin master --force
if [ "$?" = "0" ]
then
echo -e "\033[42;34m push to gitee success! \033[0m"
else
ech -e "\033[41;30m push to gitee fail! \033[0m"
exit 1
fi
3.執(zhí)行shell腳本,可以傳一個參數是git 的提交的msg:
PS:下面看下git強制覆蓋本地代碼和強制推送本地到遠程倉庫
1.git強制覆蓋本地文件(與git遠程倉庫保持一致):
git fetch --all
git reset --hard origin/master
git pull
git強制覆蓋本地命令(單條執(zhí)行):
git fetch --all git reset --hard origin/master git pull
2.git強制推送本地代碼到遠程倉庫
切換到對應的要上傳文件的文件夾下面執(zhí)行命令
git push -u origin develop
總結
到此這篇關于shell腳本一鍵同時推送代碼至github和gitee的文章就介紹到這了,更多相關shell推送代碼至github和gitee內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:- Shell腳本中管道的幾種使用實例講解
- Shell腳步攻略之管道重定向基礎
- PowerShell管道入門必看篇(管道例子大全)
- linux shell 管道命令(pipe)使用及與shell重定向區(qū)別
- PowerShell實現按條件終止管道的方法
- PowerShell中終止管道的方法
- PowerShell入門教程之PowerShell管道介紹
- Windows Powershell導出管道結果
- Windows Powershell過濾管道結果
- 如何利用 tee 命令調試shell腳本中的管道