Curriculum
Course: Git
Login
Text lesson

Git Staging Environment

Git Staging Environment

A key feature of Git is the use of the staging environment and commits.

As you work, you may add, modify, or remove files. Whenever you reach a milestone or complete part of your work, you should add these files to the staging environment.

Files in the staging environment are ready to be committed to your repository. You’ll learn more about committing later.

For now, we’ve finished working with index.html, so let’s add it to the staging environment.

Example

[user@localhost] $

git add index.html

The file should now be staged. Let’s check its status:

Example

[user@localhost] $

git status
On branch master
 No commits yet
 Changes to be  committed:
  (use  "git rm --cached ..." to unstage)
     new file: index.html

The file has now been added to the staging environment.

Git Add More than One File

You can also stage multiple files at once. Let’s add two more files to our working folder using the text editor.

First, create a README.md file to describe the repository (this is recommended for all repositories):

Example

# hello-world
Hello World repository for Git tutorial
This is an example repository for the Git tutoial on https://www.code7school.com

This repository is built step by step in the tutorial.

Next, create a basic external stylesheet named bluestyle.css:

Example

body {
background-color: lightblue;
}

h1 {
color: navy;
margin-left: 20px;
}

Then, update index.html to include the stylesheet.

Example

<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
<link rel=”stylesheet” href=”bluestyle.css”>
</head>
<body>

<h1>Hello world!</h1>
<p>This is the first file in my new Git Repo.</p>

</body>
</html>

Now, add all files in the current directory to the staging environment.

Example

[user@localhost] $

git add –all

Using –all instead of specifying individual filenames will stage all changes, including new, modified, and deleted files.

Example

[user@localhost] $

git status
On branch master
 
No commits yet
 
Changes to be committed:
(use "git rm --cached ..." to unstage)
       new file: README.md
       new file: bluestyle.css
       new file: index.html

All three files are now added to the staging environment, and we’re ready to make our first commit.

Note: The shorthand for git add –all is git add -A.