Staging Environment

Git Staging Environment

One of the core functions of Git is the concepts of the Staging Environment, and the Commit. As you are working, you may be adding, editing and removing files. But whenever you hit a milestone or finish a part of the work, you should add the files to a Staging Environment.

Staged files are files that are ready to be committed committed to the repository you are working on.

You will learn more about commit shortly. For now, we are done working with index.html. So we can add it to the Staging Environment:

$ git add index.html

$ git status
On branch master

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

Now the file has been added to the Staging Environment.

Git Add More than One File

You can also stage more than one file at a time. Let's add 2 more files to our working folder. Use the text editor again.

A README.md file that describes the repository (recommended for all repositories):

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

This repository is built step by step in the tutorial.

A basic external style sheet (mystyle.css):

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

And update index.html to include the stylesheet:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="mystyle.css">
<title>Hello World!</title>
</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:

git add .

Now all 3 files are added to the Staging Environment, and we are ready to do our first commit.

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