Git Staging Environment
Understanding Git Staging
Git has a Staging Area, which acts as a preparation zone before permanently saving changes in the repository. This step ensures that only the desired updates are included in the next commit.
Why Use the Staging Area?
While working on a project, you frequently modify, delete, or add files. Instead of committing every small change immediately, you can stage them first. This allows you to organize changes before finalizing them in the repository.
Adding Files to Staging
Once you’re done working on index.html, you can move it to the staging area using:
Example:
git add index.html
Check the staging area by executing the status command.
git status
Output:
On branch master No commits yet Changes to be committed: (use "git rm --cached <file>" to remove from staging) new file: index.html
Now, index.html is staged and ready for the next step—committing.
Staging Multiple Files
You can stage multiple files simultaneously instead of adding them individually.Let’s create two more files:
README.md (to describe the project)
# My First Git Project This repository is a demo for learning Git. Follow along to see how Git works step by step!
bluestyle.css (to style the webpage)
body { background-color: lightblue; } h1 { color: navy; Margin-left: 20px; }
Updating index.html to include the new stylesheet:
<!DOCTYPE html> <html> <head> <title>My First Git Project</title> <link rel="stylesheet" href="bluestyle.css"> </head> <body> <h1>Hello, Git!</h1> <p>Welcome to my first Git repository.</p> </body> </html>
Staging All Files at Once
Instead of adding files individually, use:
git add --all
or the shorthand:
git add -A
Now check the status again: sh Copy Edit git
git status
Output:
On branch master No commits yet Changes to be committed: (use "git rm --cached <file>" to unstage) new file: README.md new file: bluestyle.css New file: index.html
All three files are now prepared for the initial commit!
PreviousNext