Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8037179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:51:00+00:00 2026-06-05T02:51:00+00:00

I have a git controlled directory (actually my home directory) within which there are

  • 0

I have a git controlled directory (actually my home directory) within which there are ignored directories (e.g. trash space, and directories controlled by other VCSs). I want to be able to have my bash prompt show whether a directory is version controlled and if so by which VCS, but e.g. git rev-parse will always find the topmost .git directory.

Is there a way to ask git whether I’m in an untracked directory?

I’ve found this to work:

if ! git rev-parse 2>&/dev/null; then
    echo "not in git"
else
    PREFIX=$(git rev-parse --show-prefix)
    if [ -z "$PREFIX" ]; then
        echo "at git top level"
    elif [ -z $(cd $(git rev-parse --show-toplevel); \
          git ls-files -o --directory "${PREFIX%%/}")
        echo "tracked by git"
    else
        echo "untracked"
    fi
fi

However it seems very hackish and brittle. Is there a better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:51:03+00:00Added an answer on June 5, 2026 at 2:51 am

    git clean -nd approach: If it is ignored directory, then git clean -d wants to remove it, so it is easy way to check status of current directory.

    if git clean -xnd `pwd` | grep 'Would remove \./' > /dev/null; then
        echo "Inside ignored or untracked directory"
    else
        echo "Inside normal directory"
    fi
    

    Tweak git clean to change rules about untracked files. Checked in my $HOME repository.

    Note: don’t experiment with git clean without -n lightly, it can clear things from your home.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project which sources are controlled with help of git. Right now
SITUATION: I have a python library, which is controlled by git, and bundled with
I have a project that uses Serve and is version controlled using Git. Serve
I have a vb.net (visual studio 2010) project that is version controlled with git
I have a git bare repo on production server: /home/username/railsapp.git Now I would like
Is it possible to have git commit also add new files and directories? It
There is a git controlled folder on a server where the main branch is
i have git repo . Could be a very big source base like Android.
I have GIT running on a Solaris server. From a windows machine I installed
Suppose I have Git repository like this: git-repo/ directory_1/ directory_2/ directory_3/ This has a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.