How can I check if I have any uncommitted changes in my git repository:
- Changes added to the index but not committed
- Untracked files
from a script?
git-status seems to always return zero with git version 1.6.4.2.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Great timing! I wrote a blog post about exactly this a few days ago, when I figured out how to add git status information to my prompt.
Here’s what I do:
For dirty status:
For untracked files (Notice the
--porcelainflag togit statuswhich gives you nice parse-able output):Although
git diff --shortstatis more convenient, you can also usegit status --porcelainfor getting dirty files:Note: The
2>/dev/nullfilters out the error messages so you can use these commands on non-git directories. (They’ll simply return0for the file counts.)Edit:
Here are the posts:
Adding Git Status Information to your Terminal Prompt
Improved Git-enabled Shell Prompt