In this blog post, we'll be taking a look at one of the most essential parts of version control in GitHub. The article will go over what Staging & Committing is in Git, why it's important, and how to do it when making your own project changes.
What is Staging & Committing?
Imagine you are browsing your favorite online retailer, adding and removing items to your cart. That's essentially what Staging is when version controlling in Git. You're preparing your cart for the final checkout by making changes based on your needs and preferences. The key here is that nothing is permanent yet. You might be writing bug fixes or making changes to a text file, but you can keep adding and removing things during the Staging step.
Now you've finished shopping, have a full cart ready for checkout, and finally make the purchase. That's Committing. You pay for your items, get a receipt, and there is now a record of the transaction. The changes that you made during the Staging step are now actually realized and updated in your project.
Why is Staging & Committing Important?
Staging & Committing is crucial because it provides users and team members complete control over project history and allows for organized version control. Instead of submitting every bug fix all at once, you can take your time preparing the changes (stage), and then permanently record them when you're ready (commit). You can even do multiple rounds of Staging & Committing if necessary, as each round will be recorded and can be rolled back onto if any changes results in a broken product. Going back to the shopping analogy, if you don't like what you bought, you can always return it, just like rolling back on a previous version!
How to Stage & Commit in Git
Step 1:
- Check file status:
git status
Step 2:
- Pick one:
- Stage a specific file:
git add filename.filetype - Staging all files:
git add . - Unstaging a file:
git reset filename.filetype
- Stage a specific file:
Step 3:
- Save changes:
git commit -m "description of your changes"
Step 4:
- See your new commit:
git log
