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

所属分类: 脚本专栏 / linux shell 阅读数: 325
收藏 0 赞 0 分享

自己写的东西,要同时推送多个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
更多精彩内容其他人还在看

php编译安装常见错误大全和解决方法

这篇文章主要介绍了php编译安装常见错误大全和解决方法,需要的朋友可以参考下
收藏 0 赞 0 分享

Linux base shell重定向详解

这篇文章主要介绍了Linux base shell重定向的相关资料,并用一个简明例子总结了常见用法(在第三节),需要的朋友可以参考下
收藏 0 赞 0 分享

Linux Shell 常见的命令行格式简明总结

这篇文章主要介绍了Linux Shell 常见的命令行格式简明总结,非常实用,需要的朋友可以参考下
收藏 0 赞 0 分享

Shell 命令替换的两种方式

这篇文章主要介绍了Shell 命令替换的两种方式,需要的朋友可以参考下
收藏 0 赞 0 分享

Python创建、删除桌面、启动组快捷方式的例子分享

这篇文章主要介绍了Python创建、删除桌面、启动组快捷方式的例子分享,需要的朋友可以参考下
收藏 0 赞 0 分享

shell基础学习中的字符串操作、for循环语句示例

这篇文章主要介绍了shell基础学习中的字符串操作、for循环语句示例
收藏 0 赞 0 分享

shell脚本中28个特殊字符的作用简明总结

这篇文章主要介绍了shell脚本中28个特殊字符的作用简明总结,需要的朋友可以参考下
收藏 0 赞 0 分享

linux shell流程控制语句实例讲解(if、for、while、case语句实例)

linux shell有一套自己的流程控制语句,其中包括条件语句(if),循环语句(for,while),选择语句(case)。下面我将通过例子介绍下,各个语句使用方法
收藏 0 赞 0 分享

分享一个实用的iptables脚本(各种过滤写法参考)

这篇文章主要介绍了分享一个实用的iptables脚本(各种过滤写法参考),需要的朋友可以参考下
收藏 0 赞 0 分享

shell脚本实现ssh自动登录功能分享

mac下没有找到好用的类似secureCRT,就自己写了个自动登录的脚本,分享一下,如果是新浪的,就基本不用修改代码就直接能用
收藏 0 赞 0 分享
查看更多