Git & GitHub
/Intermediate
Staging Area
Definition
A file, generally contained in your Git directory, that stores information about what will go into your next commit. Its technical name in Git parlance is the 'Index'.
Explain Like I'm New
The waiting room before a photograph is taken. If you changed 10 files, but only want 3 of them to be in the photograph, you put those 3 files on the 'Stage'. When you click the camera (commit), only the files on the Stage are captured.
Real World Example
A shopping cart. You walk around the store picking up items (editing files). Putting them in your cart is 'Staging' them. Checking out at the register is the 'Commit'.
Common Use Cases
- •Grouping related changes
- •Keeping commits small and focused
Terminal Output
bash / terminal
# You edited two files: index.html and styles.css
# Move ONLY index.html to the Staging Area
$ git add index.html
# Check the status
$ git status
# Output:
# Changes to be committed (Staging Area):
# modified: index.html
#
# Changes not staged for commit (Working Directory):
# modified: styles.css
Interview Questions
basic
- What command moves files from the Working Directory to the Staging Area?
intermediate
- If you stage a file, then edit it again before committing, what happens?