Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
746 views
in Technique[技术] by (71.8m points)

windows - How to check the status of all git repositories at once?

Introduction

In order to check the status of git repositores, git status could be issued from the root of a repository.

C:pathogit_repositoriesgit_repo_1>git status
On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working directory clean

If a directory consists of multiple, e.g. 50 git repositories

C:pathogit_repositories>dir

 Directory of C:pathogit_repositories

  .ssh
  git_repo_1
  ...
  git_repo_50
   0 File(s)
   51 Dir(s)

Nor

C:pathogit_repositories>git status .
fatal: Not a git repository (or any of the parent directories): .git

neither

C:pathogit_repositories>git status ./.
fatal: Not a git repository (or any of the parent directories): .git

is able to check the status of all repositories

Question

How to check the status of all git repositories at once?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...