首页 > 解决方案 > Looking for folders containing bare git repositories

问题描述

If they were working copy of git repositories, we could start simply with the approach of looking for every folder with the name ".git" (find . -type d -name ".git"), as answered here.

But in big storages, how to detect all folders containing bare git repositories?

标签: git

解决方案


我使用以下代码:

locate -b \*.git |
    while read path; do
        if [ -f "$path" ]; then
            echo "$path is a gitlink file (perhaps in a submodule)"
        elif [ -d "$path" ]; then
            if [ "`basename \"$path\"`" = .git ]; then
                echo "$path is repository"
            else
                echo "$path is bare repo"
            fi
        fi
    done

警告 1:要使用locate,您需要将系统配置为updatedb定期运行(通常每晚从cron

警告 2:代码假设您所有的裸存储库都命名为name.git. 我的是。


推荐阅读