current directory git repository check

Check if Current Directory is a Git Repository

This article introduces how to check from the command line of Linux computers and servers if the current directory is a git repository. For Windows cmd.exe or powershell, you can do similar things by modifying the if part appropriately.

Shou Arisaka
1 min read
Nov 19, 2025

This article introduces how to check from the command line of Linux computers and servers if the current directory is a git repository. For Windows cmd.exe or powershell, you can do similar things by modifying the if part appropriately.

if git rev-parse --git-dir > /dev/null 2>&1; then
echo  " # this is a git repository"
else
echo " # this is not a git repository"
fi

This will display ”# this is a git repository” if the current directory is a git repository, and ”# this is not a git repository” if it’s not.

Note that for git repositories, “.git” is often appended to the end of the current directory path.

Share this article

Shou Arisaka Nov 19, 2025

🔗 Copy Links