gitvalidationrepositorylocalworking-copy

git check if working copy repository exists and validate it


  1. I'm looking for a way to test local directory against presence of a git repository.
    I would not like just to check by sh/bash if the .git sub directory exist but rather use dedicated git command if there is a one.

  2. I want to validate potentially found git repository in that local directory by a git command.

Do you know any git commands to do that?


Solution

  • For item 1, use git rev-parse --is-inside-work-tree. This:

    Note, however, that if you are in a Git repository whose work-tree is damaged or modified in some way, Git will print true here. If you pass --git-dir= and a path to a valid repository, Git always thinks you are in a work-tree (because you are). The exit status of this command is zero if it printed either true or false, and nonzero if it produced an error.

    For item 2—"validating" the repository—this depends entirely on what you mean by "validate".