Imagine a box. You can put stuff into the box. You can take stuff out of the box. This box is the staging area of Git. You can craft commits here. Committing is like sealing that box and sticking a label on it. The contents of that box are your changes. So, why not have the label mean something? You wouldn’t label a moving box with kitchen items as simply “stuff.”
As you make changes locally, Git can "see" them. However, figuratively speaking, they're out of the box. If you were to try and make a commit at this point, Git wouldn't have anything to commit.
Here's how to relate the box analogy to some basic Git operations.
git config --global user.name "Jonathan Irvin"
You create a seal that you will use for each box. It has your full name on it. Not a username or a screen name. That would be silly. You laugh to yourself at the silliness.
git config --global user.email "email@example.com"
You add your email address to your seal. Would be useful should someone need to contact you about the contents...or yell at you. You know, business as usual.
You build your desk and keep an infinite supply of boxes underneath the surface to place work items in for storage.
The moment you perform an add command, you're adding to the box. Yes, grab a box. Any box. Put something in it. You've just done a
Pick up the box and put it on a shelf away from your desk. Your desk is clean, but your items are still easily accessible.
git stash apply
Take the box off of the shelf and empty the contents back on to your desk...neatly. Hopefully, you don't have anything on your desk already or you might have some conflicts!
git stash clear
Take your arm and swiftly swipe all of the shelf contents into the garbage chute. Who needed all of those half-baked ideas anyway?
git reset HEAD --
Take one item out of the box.
git reset HEAD --
Take several grouped items out of the box.
git reset --hard HEAD
Pour gasoline on the box and light it on fire. Your stuff is now ashes. Gone. Forever.
git commit -m "message"
Tape the box shut. Label it with "message" and put it in storage with other labeled boxes.
Hold a mirror up to the sealed box. Magically, another box is created that appears to be an exact clone, yet completely opposite. You keep the two boxes apart for fear they would cancel each other out. It is the anti-box.
You look at your desk and see items on your desk, in the box, or both.
Now anytime you look at a box, you can't unsee it.
Claim your page on DEV before someone else does
Level up every day