Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
694 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 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...