git/list[1] front-page[2] threads[3] people[4] search[5] about
 

How to check repository/working tree status from a script

From
MHMarc Haber <mh+git@zugschlus.de>
Date
May 19, 2009, 14:35 UTC
Message-ID
<20090519143537.GA23505@torres.zugschlus.de>
Hi,

I am kind of new to git, and my thinking is still somewhat svn-centric. Please keep this in mind just in case that I have misunderstood some of git's concepts.

I would like to check in a script whether there (a) are uncommitted changes (as in "working tree differs from local repository") and/or whether there (b) are unpulled changes in the "remote origin" repository.

I have to admit that I didn't bother about (b) yet, but for (a) there seems no possibility other than to parse git status' output since it seems to always return exit code 1:

$ GIT_PAGER=cat git status; echo $? # On branch master nothing to commit (working directory clean) 1 $ touch keks $ GIT_PAGER=cat git status; echo $? # On branch master # Untracked files: # (use "git add <file>..." to include in what will be committed) # # bla nothing added to commit but untracked files present (use "git add" to track) 1 $

Am I missing something here? Is there documentation about the exit codes of the different git subcommands or probably a complete solution for my two endeavours?

Any hints will be appreciated.

Greetings Marc

-- 
-----------------------------------------------------------------------------
Marc Haber         | "I don't trust Computers. They | Mailadresse im Header
Mannheim, Germany  |  lose things."    Winona Ryder | Fon: *49 621 72739834
Nordisch by Nature |  How to make an American Quilt | Fax: *49 3221 2323190
Next: Tony Finch
Message 1 of 15 in “How to check repository/working tree status from a script”
  1. Marc HaberMay 19, 2009
  2. Tony FinchMay 19, 2009
  3. Marc HaberMay 19, 2009
  4. Tony FinchMay 19, 2009
  5. Marc HaberMay 20, 2009
  6. Linus TorvaldsMay 19, 2009
  7. Linus TorvaldsMay 19, 2009
  8. Marc HaberMay 20, 2009
  9. Marc HaberMay 20, 2009
  10. Santi BéjarMay 20, 2009
  11. Johannes SixtMay 20, 2009
  12. Marc HaberMay 20, 2009
  13. Marc HaberMay 21, 2009
  14. Jeff KingMay 21, 2009
  15. Marc HaberMay 23, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.