How can I view all the git repositories on my machine?

前端 未结 10 798
南旧
南旧 2020-11-29 21:00

Is there a way in which I can see all the git repositories that exist on my machine? Any command for that?

10条回答
  •  渐次进展
    2020-11-29 21:22

    Git repositories all have HEAD, refs and objects entries.

    on GNU/anything,

    find -name HEAD -execdir test -e refs -a -e objects \; -printf %h\\n
    

    Just checking for .git will miss many bare repos and submodules.

    To go full-paranoid on the checking you can ask git to do all its own checks before printing,

    find -name HEAD -execdir test -e refs -a -e objects \; \
          -execdir sh -ec 'GIT_DIR=$PWD git rev-parse --absolute-git-dir 2>&-' \;
    

    (edit: I thought the .git/config file was necessary, turns out it's not, so the absolute minimum git init newrepo is

    mkdir -p newrepo/.git/{objects,refs}
    echo ref: refs/heads/master >newrepo/.git/HEAD
    

    )

提交回复
热议问题