Git: how to find git repository directories

To find many git repository directories on your local system, we use the find command:

  find ~ -type d -name .git

Sample result:

  ~/foo/.git
  ~/bar/baz/.git
  ~/some/other/directory/.git

To use "find"

We use these find command options:

  • tilde says to search everything with our home directory
  • -type d searches for directories, not files
  • -name .git searches for the name ".git" which is a repository

To learn more about find, search the net for: unix man page find

To chop the git repository: xargs dirname

To chop off the .git repository from the directory path, we use the xargs and dirname command:

  find ~ -type d -name .git | xargs -n 1 dirname

Sample result:

  ~/foo
  ~/bar/baz
  ~/some/other/directory

To learn more about dirname, search the net for: unix man page dirname

To learn more about xargs, search the net for: unix man page xargs



What's Next?

blog comments powered by Disqus



WebGet SixArm • http://webget.com • Copyright © 2010 • All Rights Reserved