Version Control
Git: Getting started
Git: Getting started
  • Introduction
    • What is version control
      • Distributed VCS
      • Summary
    • What is Git?
      • A Short History of Git
      • Under the hood
      • The Three States
    • What is GitHub?
  • Setting up Git
    • Installation
    • First time setup
    • Creating a repo
  • Basic operations
    • Recording Changes
      • Add another file
      • Modify-stage-commit
      • Modify-direct commit
      • View log
    • Undo changes
      • Restore (modified)
      • Restore (staged)
      • Amend (rare)
    • Clone repos
  • Remote Repos
    • Configure remote
    • Push to remote
      • Push branches
  • Reference
    • My Git Tutorials
    • Git Official
    • Others
Powered by GitBook
On this page
  • Recording Changes
  • States of a file
  • Check the status
  • Adding or tracking new files
  • Committing changes
  • Let us check the status again
  1. Basic operations

Recording Changes

PreviousCreating a repoNextAdd another file

Last updated 2 years ago

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:

  • 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

When you first create a repository, all of your files will be untracked because we have not instructed anything about it to Git!

Check the status

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

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

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

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

You can tell that it’s staged because it’s under the “Changes to be committed” heading!

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

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

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

It is recommended to use double quotes on Windows platform and single quote on Linux platform!

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

  • which branch you committed to (master),

  • what checksum the commit has (b1e291c),

  • how many files were changed, and

  • statistics about lines added and removed in the commit.

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

Every time you perform a commit, you’re recording a snapshot of your project that you can revert to or compare to later!

Let us check the status again

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

git status
On branch master
nothing to commit, working tree clean

The message we get from Git is self-explanatory.

The lifecycle of the status of your files