Check status of all git repositories at once

别来无恙 提交于 2019-11-29 11:11:23

You could use a for loop that changes into each directory, does git status and then changes back up:

for /f "tokens=*" %a in ('dir /ad /b') do cd %a & git status & cd ..

You need to double the percentages if you use this in a batch file:

for /f "tokens=*" %%a in ('dir /ad /b') do cd %%a & git status & cd ..

Edit:

As suggested by Cupcake, you could do this instead:

for /f "tokens=*" %a in ('dir /ad /b') do git --git-dir=%a/.git --work-tree=%a status

This feels like a more robust and flexible solution (e.g. you could adapt it more easily to work with a list of paths stored in a text file).

I went with:

find . -name .git -execdir bash -c 'echo -en "\033[1;31m"repo: "\033[1;34m"; basename "`git rev-parse --show-toplevel`"; git status -s' \;

I think it's nicer because treats directories recursively.

Edited to show the name of the repo in a cleaner way.

If you are a kind of a tool-guy, you could use a little helper called RepoZ I wrote recently (and still write).

I answered a quite similar question in more detail here.

Here's a screenshot from the current development stage so hopefully you can see whether it seems helpful to you or not:

If you are wondering what that strings like +45 ~403 -88 mean - they are condensed status strings telling you whether there are commits to fetch or push and whether there are added/modified/deleted files locally. More detail on the project site on GitHub

If you have a system that is made up of numerous Git repositories, that is possibly a situation for which the Google repo tool was created: https://code.google.com/archive/p/git-repo/

If you find yourself writing scripts to distribute Git commands over these repositories, you should probably switch to repo.

repo works with an (unfortunately) XML file called the "manifest.xml" which specifies the Git repositories that are in the workspace. For each repo specifies which branch and commit should appear; you can use repo to "pin" the Git repositories to particular versions, or to track heads.

If you have a repo workspace then

$ repo status

then repo will do pretty much what you're asking for: iterate over the Git repos and give you a status.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!