Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Adding New Files | Introduction to Git
Git Essentials

bookAdding New Files

Creating a Text File

Create a text file in your project directory so that the working tree is no longer empty. Use the echo command to do this:

'Learning Git is cool!' is the text content to be written to the file. The single quotes are used only for enclosing the text and are not included in the file. By default, the echo command prints text to the terminal, but the output redirection operator > redirects it to the test.txt file.

Now, run the git status command:

Creating a new text file

There is now a file in the working tree, but it is currently untracked by Git. To make it tracked, add the file to the staging area.

Adding to the Staging Area

The staging area, also known as the "index", is a file which serves as an intermediate step between your working directory and the Git repository itself. It contains information regarding the changes and files which will be included in the next commit.

A commit is a fundamental operation that records changes made to files in your Git repository. Essentially, when you commit, you are creating a snapshot of your project at a particular point in time and store it.

The command to add a file to the staging area is as follows:

git add <file>

<file> should be replaced with the name of the file or its path relative to your project's root directory if the file is located in a specific directory within your project. The command looks as follows for us:

Add the test.txt file to the staging area and then check the status of both the working tree and the staging area:

Adding a new file to the staging area
Note
Note

In fact, the git status command displays the state of both the working directory and the staging area.

As you can see, test.txt has been added to the staging area, representing a single change ready to be committed – the addition of a new file. Here is an illustration to make things clear:

Adding a new file
question mark

How to add a file named data.csv to the staging area?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 7

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

What does the staging area do in Git?

How do I commit the changes after adding a file to the staging area?

Can I add multiple files to the staging area at once?

Awesome!

Completion rate improved to 3.57

bookAdding New Files

Swipe to show menu

Creating a Text File

Create a text file in your project directory so that the working tree is no longer empty. Use the echo command to do this:

'Learning Git is cool!' is the text content to be written to the file. The single quotes are used only for enclosing the text and are not included in the file. By default, the echo command prints text to the terminal, but the output redirection operator > redirects it to the test.txt file.

Now, run the git status command:

Creating a new text file

There is now a file in the working tree, but it is currently untracked by Git. To make it tracked, add the file to the staging area.

Adding to the Staging Area

The staging area, also known as the "index", is a file which serves as an intermediate step between your working directory and the Git repository itself. It contains information regarding the changes and files which will be included in the next commit.

A commit is a fundamental operation that records changes made to files in your Git repository. Essentially, when you commit, you are creating a snapshot of your project at a particular point in time and store it.

The command to add a file to the staging area is as follows:

git add <file>

<file> should be replaced with the name of the file or its path relative to your project's root directory if the file is located in a specific directory within your project. The command looks as follows for us:

Add the test.txt file to the staging area and then check the status of both the working tree and the staging area:

Adding a new file to the staging area
Note
Note

In fact, the git status command displays the state of both the working directory and the staging area.

As you can see, test.txt has been added to the staging area, representing a single change ready to be committed – the addition of a new file. Here is an illustration to make things clear:

Adding a new file
question mark

How to add a file named data.csv to the staging area?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 7
some-alt