制作一个shell脚本来更新3 git repos [英] Make a shell script to update 3 git repos

查看:87
本文介绍了制作一个shell脚本来更新3 git repos的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用我在开发环境中克隆的5个回购协议。
当我想更新一个git仓库时,我进入文件夹/ home / adrian / repo1 /并执行:

git checkout master
git拉原产主人


但是,每天早上我必须为其他4回购做同样的事情。这很麻烦。

我可以把它放在shell脚本中吗?我的意思是,如果我在shell脚本中编写这些git命令并运行它,我是否可以更新所有repos?



我正在考虑编写类似这... ...
$ b $ pre $ $ coded $ cd $ $ b $ git checkout master $ b $ git pull origin master
cd ..
cd repo2
git checkout master
git pull origin master
cd ..

(我在linux上)



编辑:也许这比我想象的更具挑战性。大多数时候,当我做git pull origin master时,我会得到类似你的本地变化......将被合并覆盖这样的erorrs。所以,我必须进入各自的分支,并藏起来的东西..



编辑2:



我想要做的是,如果发生冲突,请忽略它并转到下一个回购站点。

  cd repo1 
git checkout master
git pull origin master

(如果有冲突,忽略并转到下一行但不要停在这里)

cd ..
cd repo2
git checkout master
git pull origin master
cd ..

但是我不知道如何在括号中写下这个东西。

首先,我建议不要使用 git pull 。相反,创建一个更安全的 git up 别名:

  git config --global alias.up'!git remote update -p; git merge --ff-only @ {u}'

请参阅这个答案来解释 git up



然后您可以安全地编写脚本:
$ b

 #!/ bin / sh 
回购repo1 repo2 repo3 repo4;做
(cd$ {repo}&& git checkout master&& git up)
完成


I am working with 5 repos that I have cloned in my development environment. When I want to update a git repo, I enter the folder /home/adrian/repo1/ and do:

git checkout master git pull origin master

But then, every morning I have to do the same thing for the other 4 repos. This is quite troublesome.

Can I put this in a shell script? I mean, if I write these git commands in the shell script, and run it, will I be able to update all the repos?

I was thinking of writing something like this...

cd repo1
git checkout master 
git pull origin master
cd ..
cd repo2
git checkout master 
git pull origin master
cd ..

(i'm on linux)

Edit: Maybe this is more challenging than what I thought. Most times when I do "git pull origin master", i get erorrs like "Your local changes to .... would be overwritten by merge." So i have to enter into the respective branch and stash the stuff..

Edit 2:

What I'm thinking of doing is, if a conflict happens, ignore it and go to the next repo

cd repo1
git checkout master 
git pull origin master

(if there is conflict, ignore and go to the next line but dont stop here)

cd ..
cd repo2
git checkout master 
git pull origin master
cd ..

but i dont know how to write the thing in parenthesis.

解决方案

First, I recommend against using git pull. Instead, create a safer git up alias:

git config --global alias.up '!git remote update -p; git merge --ff-only @{u}'

See this answer for an explanation of git up.

Then you can safely script it:

#!/bin/sh
for repo in repo1 repo2 repo3 repo4; do
    (cd "${repo}" && git checkout master && git up)
done

这篇关于制作一个shell脚本来更新3 git repos的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆