如何从共享父目录更新多个git存储库,而不用cd'ing到每个repo的根目录?我有以下所有单独的git存储库(不是子模块):

/plugins/cms
/plugins/admin
/plugins/chart

我想一次更新它们,或者至少简化我当前的工作流程:

cd ~/plugins/admin
git pull origin master
cd ../chart
git pull

etc.


当前回答

我的拙见是

显示当前路径(使用python,方便和只是工作,参见如何获得文件的完整路径?) 直接查找.git子文件夹:在非git子文件夹中发出git命令的几率很低 删除一些查找警告

遵循:

find . \
    -maxdepth 2 -type d \
    -name ".git" \
    -execdir python -c 'import os; print(os.path.abspath("."))' \; \
    -execdir git pull \;

当然,你也可以添加其他带有-execdir选项的git命令,例如显示分支:

find . \
    -maxdepth 2 -type d \
    -name ".git" \
    -execdir python -c 'import os; print(os.path.abspath("."))' \; \
    -execdir git branch \;
    -execdir git pull \;

其他回答

这应该是自动发生的,只要cms, admin和chart都是存储库的一部分。

一个可能的问题是这些插件都是git子模块。

运行git帮助子模块查看更多信息。

EDIT

在bash中这样做:

cd plugins
for f in cms admin chart
do 
  cd $f && git pull origin master && cd ..
done

如果你有很多git仓库的子dirs,你可以使用parallel

ls | parallel -I{} -j100 '
  if [ -d {}/.git ]; then
    echo Pulling {}
    git -C {} pull > /dev/null && echo "pulled" || echo "error :("
  else
     echo {} is not a .git directory
  fi
'

我从一些评论和回答中总结了几点:

find . -maxdepth 1 -type d -name .git -execdir git pull \;

mr实用程序(又名myrepos)为这个问题提供了一个出色的解决方案。使用您最喜欢的包管理器安装它,或者直接从github中抓取mr脚本,并将其放在$HOME/bin或PATH上的其他地方。然后,cd到这些repo共享的父插件文件夹,并创建一个基本的.mrconfig文件,内容类似于以下(根据需要调整url):

# File: .mrconfig
[cms]
checkout = git clone 'https://<username>@github.com/<username>/cms' 'cms'

[admin]
checkout = git clone 'https://<username>@github.com/<username>/admin' 'admin'

[chart]
checkout = git clone 'https://<username>@github.com/<username>/chart' 'chart'

After that, you can run mr up from the top level plugins folder to pull updates from each repository. (Note that this will also do the initial clone if the target working copy doesn't yet exist.) Other commands you can execute include mr st, mr push, mr log, mr diff, etc—run mr help to see what's possible. There's a mr run command that acts as a pass-through, allowing you to access VCS commands not directly suported by mr itself (e.g., mr run git tag STAGING_081220015). And you can even create your own custom commands that execute arbitrary bits of shell script targeting all repos!

Mr是处理多重回购的一个非常有用的工具。由于plugins文件夹在您的主目录中,您可能对vcsh也感兴趣。与mr一起,它为管理所有配置文件提供了强大的机制。请参阅Thomas Ferris Nicolaisen的这篇博客文章来了解概述。

Gitfox是一个在所有子回购上执行命令的工具

npm install gitfox -g
g pull