bash - Git 通过 bash 脚本推送到各种存储库
问题描述
我正在尝试创建一个 bash 脚本,该脚本迭代 4 个不同的文件夹(git 存储库)并更新/推送每个文件夹的更改。我的脚本大部分都完成了,除了身份验证部分。
这是我当前的脚本:
#!/bin/bash
# Fetch username and password
echo "Please insert your git credentials!"
read -p 'Username: ' username
read -sp 'Password: ' password
# Check if you svn and git installed in your machine
if which svn &> /dev/null && which git &> /dev/null; then
# Store the current dir
CUR_DIR=$(pwd)
# Let the person running the script know what's going on.
echo "Pulling in latest changes for all repositories..."
for D in $CUR_DIR/*; do
if [ -d "${D}" ]; then
echo "${D}"
cd $(basename $D);
# Make sure SVN is on trunk branch and git branch is on master
SVN_BRANCH=$(svn info | grep '^URL:' | egrep -o '(tags|branches)/[^/]+|trunk' | egrep -o '[^/]+$')
GIT_BRANCH=$(git symbolic-ref --short HEAD)
if [ "$SVN_BRANCH"!="trunk" ] || [ "$GIT_BRANCH"!="master" ]; then
echo $CUR_DIR
echo "Make sure you're on SVN trunk branch and git master branch."
exit -1
fi
echo "Update SVN repository";
svn up
# Update git
git add .;
git commit -m "Update with the changes from svn trunk branch."
echo "Start pushing changes to main repository."
git push origin master
echo "Update git repository";
git pull origin master
# Update SVN
svn add .
svn commit -m "Update with changes from git master branch."
cd ..
fi
echo "Complete!"
done
else
echo "You need both svn and git CLI's installed to run this script!";
fi
如您所见,我已经在脚本开头获取凭据,我的问题是如何使用它们来执行需要身份验证的操作,即
git push origin master
git pull origin master
如何构建 git 命令来发出经过身份验证的请求?
解决方案
推荐阅读
- laravel - 重复突变体
- excel - PowerShell 使用单独的相应 csv 文件更新工作簿(Excel 文件)中的多个工作表
- electron - 使用快捷键 CTRL + 减号按钮的电子块
- android - Android 放大动画
- python - RPyC:无法保存图像文件
- vue.js - Vue.js:未在 dist 文件夹中获取外部组件 datetimepicker 的 CSS 参考
- r - unlist(lapply(mydata, function(x) {x$getElementText()})) 之后如何保持值的原始格式
- c# - 如何阻止未阻止的 .net 程序集
- reactjs - 初学者 ReactJS
- java - 仅使用 Thymeleaf 为初学者制作一个简单的 Java 应用程序(没有任何与 Sping 相关的内容)