Tracking Changes - 5.6 | Chapter 5: Git and GitHub Basics – Tracking and Sharing Your Code | Full Stack Web Development Basics
K12 Students

Academics

AI-Powered learning for Grades 8–12, aligned with major Indian and international curricula.

Academics
Professionals

Professional Courses

Industry-relevant training in Business, Technology, and Design to help professionals and graduates upskill for real-world careers.

Professional Courses
Games

Interactive Games

Fun, engaging games to boost memory, math fluency, typing speed, and English skills—perfect for learners of all ages.

games

Interactive Audio Lesson

Listen to a student-teacher conversation explaining the topic in a relatable way.

Creating a File

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

Alright everyone, let's start by creating a file. Can anyone tell me how we might create a new HTML file using Git commands?

Student 1
Student 1

Do we use the touch command?

Teacher
Teacher

Great thought! We can indeed use `touch`, but here we’ll create it with `echo`. Can anyone try to recall what the command looks like?

Student 2
Student 2

Is it `echo "Hello World" > index.html`?

Teacher
Teacher

Exactly! That creates a file named `index.html` with 'Hello World' inside it. Remember, this sets the stage for our file in Git.

Checking File Status

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

Now that we've created our file, what’s the next step? How can we check if Git is tracking it?

Student 3
Student 3

We can use `git status` to check the file's status.

Teacher
Teacher

Correct! When you run `git status`, what does it tell you about our file?

Student 4
Student 4

It says the file is untracked.

Teacher
Teacher

Yes! It means Git knows the file exists but isn’t tracking it yet. We need to stage it next.

Adding the File

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

To track our changes, we now have to add the file. What command do we use?

Student 1
Student 1

We use `git add index.html`, right?

Teacher
Teacher

Excellent! This stages the file, making it ready for commit. Why is staging important?

Student 2
Student 2

It allows us to select which changes we want to commit.

Teacher
Teacher

Exactly! It gives us control over our commits.

Committing Changes

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

Finally, after staging our changes, how do we commit them?

Student 3
Student 3

We use `git commit -m"Some message"`.

Teacher
Teacher

Great! Why should we write a meaningful message?

Student 4
Student 4

So, we have a clear history of what changes were made and why.

Teacher
Teacher

That's right! Well done, everyone. Each commit serves as a snapshot of our project.

Introduction & Overview

Read a summary of the section's main ideas. Choose from Basic, Medium, or Detailed.

Quick Overview

This section explains how to track changes in your files using Git, detailing the process of creating, adding, and committing files.

Standard

In this section, you will learn the essential steps to track changes in your code with Git. This involves creating files, checking their status, staging them for commit, and finally saving those changes to the repository with clear messages that help document the changes made.

Detailed

Tracking Changes

In this section, we will explore how to effectively track changes made to your files using Git. The process to track changes includes multiple steps that are essential for maintaining version control in your projects.

Steps to Track Changes:

  1. Creating a File: Use the echo command to create a new file
Code Editor - bash

This command will create a new HTML file named index.html containing the text "Hello World".

  1. Check File Status: After creating the file, use the git status command to check its status. Here, Git will inform you that the file is untracked, meaning it exists, but Git is not yet tracking the changes.
Code Editor - bash

This will show you the current state of the repository.

  1. Adding the File to Git: Once the file is created and checked, stage it for commit using the git add command.
Code Editor - bash

This tells Git that you want to include the changes made to index.html in the next commit.

  1. Committing the File: Finally, save the staged changes with a commit command that includes a meaningful message describing the changes made.
Code Editor - bash

This command creates a snapshot of the project, which allows you to track what changes were made and why, which is crucial for project management and collaboration.

By following these steps, you can effectively track changes in your files and ensure that your project maintains a thorough history of edits.

Audio Book

Dive deep into the subject with an immersive audiobook experience.

Step 1: Create a File

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

echo "Hello World" > index.html

Detailed Explanation

In this step, you create a new file named index.html and write Hello World into it. The command echo outputs the text followed by the > operator, which redirects that output into a new file. If the file doesn't exist, it will be created. This is your first step to start tracking changes with Git.

Examples & Analogies

Think of it like writing the first sentence of a new story. Just as you need that first sentence to begin crafting your narrative, in Git, you need your first file to start tracking changes.

Step 2: Check Status

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

git status

Detailed Explanation

The git status command is used to check the current state of the repository. After creating the file, this command will show that index.html is untracked, meaning that Git is aware of its existence, but it has not yet been added to tracking. This helps you to see what files are currently being tracked and which are not.

Examples & Analogies

Imagine a librarian checking the new arrivals in a library. The librarian knows the books are there but hasn't yet entered them into the system. Just like that, git status informs you about the files that are there but not yet managed by Git.

Step 3: Add the File to Git

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

git add index.html

Detailed Explanation

The git add command stages the file for committing. This means you are telling Git that you want to track changes to index.html. Once you run this command, the file is marked as ready to be saved in the next commit. Staging files allows you to selectively choose which changes to include in your next commit.

Examples & Analogies

Think of this like placing a book in the checkout queue at a library. You select it from the shelf and indicate that you want to borrow it. Similarly, when you add a file, you are saying to Git, 'I want to include this file in my next saved version.'

Step 4: Commit (Save the File)

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

git commit -m "Added index.html"

Detailed Explanation

The git commit command takes everything you've staged and saves it to the repository history, along with a message describing the change. The message "Added index.html" gives context for this commit, making it easier to understand in the future what this change was about. Each commit represents a snapshot of your project at a specific point in time.

Examples & Analogies

It's like taking a snapshot of a moment in your life. When you take a photo, you want to remember that exact moment, and you might even add a caption to explain it. In Git, your commit is that snapshot, capturing your project's state and allowing you to look back at any point in time.

Definitions & Key Concepts

Learn essential terms and foundational ideas that form the basis of the topic.

Key Concepts

  • Creating a File: The process of generating a file in your Git repository using commands.

  • File Status: Using git status to check if a file is tracked by Git.

  • Staging: The process of adding a file with git add to prepare it for commit.

  • Committing: Saving staged changes with a message using git commit.

Examples & Real-Life Applications

See how the concepts apply in real-world scenarios to understand their practical implications.

Examples

  • To create a file called index.html, you would run the command echo "Hello World" > index.html.

  • After creating a file, running git status shows its tracking status as untracked if it has not been staged.

Memory Aids

Use mnemonics, acronyms, or visual cues to help remember key information more easily.

🎵 Rhymes Time

  • To make your files, don't hesitate, with echo the new ones will create.

📖 Fascinating Stories

  • Imagine a librarian who needs to track the books. Each time a new book arrives, she checks it in; if she forgets to update the catalog, the book becomes untracked in the library's system.

🧠 Other Memory Gems

  • Use A.C.C.: A for Add, C for Commit, C for Check status — a sequence to remember Git's workflow.

🎯 Super Acronyms

SAC

  • Staging
  • Adding
  • Committing – the three essentials in Git.

Flash Cards

Review key concepts with flashcards.

Glossary of Terms

Review the Definitions for terms.

  • Term: Git

    Definition:

    A version control system used to track changes in source code during software development.

  • Term: Repository

    Definition:

    A storage space where your project files and history of changes are stored.

  • Term: Commit

    Definition:

    A snapshot of changes made to files in a repository, along with a message describing those changes.

  • Term: Staging

    Definition:

    The process of preparing changes to be committed in Git.