shell脚本一键同时推送代码至github和gitee的解决办法

(编辑:jimmy 日期: 2024/11/11 浏览:2)

自己写的东西,要同时推送多个git地址,解决办法如下:

1.先要初始化你的git

             进入自己的项目目录,然后执行 git  init

cd /app/code/go-study
git init

2.执行以下脚本:

#!/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.执行shell脚本,可以传一个参数是git 的提交的msg:

./shell.sh "提交代码"

PS:下面看下git强制覆盖本地代码和强制推送本地到远程仓库

1.git强制覆盖本地文件(与git远程仓库保持一致):

git fetch --all
git reset --hard origin/master
git pull
git强制覆盖本地命令(单条执行):
git fetch --all && git reset --hard origin/master && git pull

2.git强制推送本地代码到远程仓库

切换到对应的要上传文件的文件夹下面执行命令

git push -u origin develop

总结