Copied from the bash completion file, the following is a naive way to do it
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
if [ -d .git ]; then
echo .git;
else
git rev-parse --git-dir 2> /dev/null;
fi;
You could either wrap that in a function or use it in a script.
Condensed into a one line condition suitable for bash and zsh
[ -d .git ] && echo .git || git rev-parse --git-dir > /dev/null 2>&1
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…