In this lesson, you will learn how to combine the staging and committing steps into one efficient operation to speed up your daily workflow.
The Two-Step Dance
So far, you’ve learned that the standard Git workflow involves two distinct actions: staging your files with git add and then capturing a snapshot with git commit. While this manual process is excellent for fine-grained control—especially when you want to group specific changes into atomic commits—it can become repetitive when you are simply saving updates to files that Git is already tracking.
The Power of the Shorthand
When you are working on a project and have already "tracked" your files (meaning they have been added to the repository previously), you don’t necessarily need to run git add separately. You can use the -a flag combined with the -m flag to perform both tasks at once.
To stage all tracked modifications and commit them in one go, use the following command:
git commit -a -m "Your descriptive commit message"
Here is how this command breaks down:
-a: Tells Git to automatically stage every file that has been modified or deleted. Note that this only applies to files that are already tracked by Git.-m: Allows you to provide your commit message directly in the command line, skipping the need to open your default text editor.
When to Use This
This workflow is a huge time-saver when you are working on a feature and have finished updating several existing files. Instead of adding each one individually, git commit -a handles the heavy lifting for you.
However, remember one critical limitation: this command will not stage new files. If you create a brand-new file, Git doesn't know about it yet, so you must still use git add for new files before you can include them in a commit. By mastering this balance, you can maintain a fast, efficient workflow without losing the clarity required for high-quality version control.
Key Takeaway: Use git commit -a -m "message" to quickly stage and commit changes to your already tracked files in a single, efficient step.