Taggit

Get status of git repositories in directory

I have a development directory (~/dev) which houses all of my git repositories.
Recently I bought another laptop, but to make sure I pushed all my local development I check the status of the git repositories with the following bash script:

#!/bin/bash

gitrepos=`find . -type d -name ".git" -prune -print | xargs -I {} dirname {}`

for repo in $gitrepos; do
  pushd $PWD > /dev/null
  cd $repo
  # echo $PWD
  if git diff-index --quiet HEAD --; then
    echo -e "UP TO DATE\t - $repo"
  else
    echo -e "CHANGES\t\t - $repo"
  fi
  popd > /dev/null
done

Place the code above in a file e.g. repostatus.sh and make it executable: chmod +x repostatus.sh.

Restore a deleted file in git

Git is your lifesaver if you have deleted a file somewhere in the past and committed that change.

Due to the nature of Git that file is not gone, but just hidden.
You can retrieve that file by using “checkout”.

You should select the commit before the file got deleted or you’ll see an:

error: pathspec '<your-file-to-retrieve>' did not match any file(s) known to git.

So, suppose your commit is at 48b8bc and you want to retrieve some-file.txt:

git checkout 48b8bc -- some-file.txt

Now the file you were looking for should be in your new files when checking it with: “git status”.

Git status of multiple git repositories in one directory

If a project consists of multiple git repositories I’d like to see if I forgot to create a commit in one of them at the end of a development day.

This little bash script traverses all directories with a .git directory and checks with a ‘git status’ what the status of that git repository is.

Handy! I’d use it, if it were me!

for x in $(find . -type d -name ".git"); do pushd $(dirname $x); pwd; git status; popd; done

© 2025 Roholt

Thema door Anders NorénOmhoog ↑