A bash script that saves me from git -m “I forgot git add”

David Guan
2 min readJun 3, 2018

It happened multiple times recently: after carefully checking every line of code locally and git commit -am “the feature-x”; git push. 10 mins later: The CI failed on my branch!!??? -> finding out it’s caused by the file not found error 🤦‍

By adding a -theCountOfPendingFiles to the shell prompt(as the image below), I won’t worry about making that mistake again :)
(Providing untracked-files confirmation with git pre-push hook is another choice, but I think that’s maybe an overkill.)

Putting the code below into the bash loading file(like ~/.bash_profile for MacOS) will make it work:

Background

My knowledge around shell was insufficient, so I spent a big chunk of time this weekend on reading the remarkable book The Linux Command Line.

The author uploaded it to a sourceforge repo

Learned a lot from the book, when I was thinking about something to practice, the idea of fixing the “I forgot git add again” just came into mind(will automate more manual work like this in the future for sure).

Frankly, my knowledge was so limited that I learned a ton from this book, including but not limited to:

  • Permissions stuff, things like why we need sudo instead of using the root user directly?
You should also read the book if you don’t understand some stuff from ls -l 😝
  • Basic bash scripting.
  • Hard and symbolic link, and how to identify them.
  • Redirection stdin/err with >, >> and more.
  • Expansions(brace expansion for example).
  • Processes stuff and what machines do when we tell them kill -9 some process.
  • And more…

Definitively recommend the book 😃

--

--

David Guan

I program machines to do web and graphics stuff, also write about them.