# Recording Changes

## Recording Changes

### States of a file

At this point, you should have a *real* Git repository on your local machine, and all of its files in front of you. Typically, you’ll want to start making changes and committing snapshots of those changes into your repository each time the project reaches a state you want to record.

Remember that each file in your **working directory** can be in one of two **states**:&#x20;

* Untracked state
  * Untracked files are not the files which git is simply not interested in
* Tracked state
  * Tracked files are files that Git knows about
  * Tracked files are files that were in the last snapshot, as well as any newly staged files
  * Files which are in tracked **state** can be in any one of the **condition** below
    * Unmodified condition
    * Modified condition
    * Staged condition

{% hint style="info" %}
When you first create a repository, all of your files will be `untracked` because we have not instructed anything about it to Git!
{% endhint %}

<figure><img src="https://2337445475-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsfCpkRnlznioR5UYwXB9%2Fuploads%2FDjEAeyDd3rK199OxqTRO%2Fimage.png?alt=media&#x26;token=e1b76897-a181-4d95-b9b5-df3cd9538da6" alt=""><figcaption><p>The lifecycle of the status of your files</p></figcaption></figure>

### Check the status

Let us check the status of our working directory with the below command

```bash
git status
```

```
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        hello.txt

nothing added to commit but untracked files present (use "git add" to track)
```

We can see that the file is in untracked state

### Adding or tracking new files <a href="#tracking_files" id="tracking_files"></a>

In order to begin tracking a new file, you use the command `git add`. To begin tracking the `hello.txt`file, you can run this:

```bash
git add hello.txt
```

If you run your status command again, you can see that your file is now tracked and staged to be committed:

```
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   hello.txt
```

{% hint style="info" %}
You can tell that it’s **`staged`** because it’s under the **“Changes to be committed”** heading!
{% endhint %}

Note: The `git add` command takes a path name for either a file or a directory; if it’s a directory, the command adds all the files in that directory recursively.

### Committing changes&#x20;

Let us commit the changes to our local repository using the below command

```bash
git commit -m "initial content"
```

```
[master (root-commit) b1e291c] initial content
 1 file changed, 1 insertion(+)
 create mode 100644 hello.txt
```

{% hint style="info" %}
It is recommended to use double quotes on Windows platform and single quote on Linux platform!
{% endhint %}

Now you’ve created your first commit! You can see that the commit has given you some output about itself:&#x20;

* which *branch* you committed to (`master`),&#x20;
* what *checksum* the commit has (`b1e291c`),&#x20;
* how many files were changed, and&#x20;
* statistics about lines added and removed in the commit.

Note: we will discuss branch later, checksum is a unique identifier issued by git database.

{% hint style="info" %}
Every time you perform a commit, you’re recording a **snapshot** of your project that you can revert to or compare to later!
{% endhint %}

### Let us check the status again&#x20;

Let us check the status again to confirm if our commit went through by using the same command we used earlier:

```bash
git status
```

```
On branch master
nothing to commit, working tree clean
```

The message we get from Git is self-explanatory.
