简体   繁体   English

使用Bash脚本在平均堆栈项目中运行多个git命令?

[英]Run multiple git commands in a mean stack project using Bash script?

We are using multiple branches (development, testing and master). 我们正在使用多个分支(开发,测试和掌握)。 Now the site is done with the most part of the application and bugs are solved. 现在,该站点已完成大部分应用程序的工作,并且已解决了一些错误。 Everytime i have to push the changes on development branch from my local system and login onto server, go to the path and run these commands: 每当我必须将更改从本地系统推送到开发分支上并登录到服务器时,转到路径并运行以下命令:

  1. git checkout development git checkout开发
  2. git pull origin development git pull起源开发
  3. git checkout testing git checkout测试
  4. git merge origin development git merge起源开发

Can we make these 4 commands into one? 我们可以将这四个命令合而为一吗?

EDIT: I created the bash script but how to add the pasword in the script ? 编辑:我创建了bash脚本,但是如何在脚本中添加密码呢?

#!/bin/bash  
echo "This is a shell script"  
git status
git pull origin development

?

If you setup gitcredentials ( https://git-scm.com/docs/gitcredentials.html ) you should be able to script all of it like that: 如果您设置gitcredentials( https://git-scm.com/docs/gitcredentials.html ),则应该能够对所有脚本进行如下编写:

#!/bin/bash  
echo "This is a shell script"  
my_pass="awesomePassword"
server="awesomeServer"

sshpass -p $my_pass ssh $server "git status; git pull origin development; git checkout testing; git merge origin development"

(untested) You will have to install sshpass and you should note that it is not really a good practice to hardcord passwords like that. (未测试)您将必须安装sshpass,并且应注意,对这样的硬密码进行密码并不是真正的好习惯。 Could be avoided by using user input. 可以通过使用用户输入来避免。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM