Computer Science Grade 9 20 min

2. Introduction to Git

Introduce Git as a popular version control system.

Tutorial Preview

1

Introduction & Learning Objectives

Learning Objectives Define what a Version Control System (VCS) is and explain its purpose. Initialize a new local Git repository in a project folder. Describe the function of the working directory, staging area, and repository. Use the `git add` command to stage changes for a commit. Use the `git commit` command to save a snapshot of their project. Write a clear and descriptive commit message. Use `git status` and `git log` to check the state and history of their repository. Ever saved a file as `project_final.docx`, then `project_final_v2.docx`, then `project_REALLY_final.docx`? 📝 What if there was a 'time machine' for your code? In this lesson, you will learn about Git, a powerful tool used by developers worldwide to track changes in their code. Think of it a...
2

Key Concepts & Vocabulary

TermDefinitionExample Version Control System (VCS)A tool that tracks and manages changes to files over time. It allows you to recall specific versions later, compare changes, and see who made them.Google Docs' version history is a simple type of VCS. Git is a much more powerful VCS designed specifically for code. Repository (Repo)A folder that contains all your project's files and the entire history of changes. It's the 'database' where Git stores everything.If you have a project folder called `my-game`, the Git repository would be a hidden `.git` subfolder inside it that tracks everything. CommitA snapshot of your project's files at a specific point in time. It's like a permanent save point in a video game.After you finish coding a player's jump me...
3

Core Syntax & Patterns

Initializing a Repository git init Run this command one time inside your main project folder. It creates a new, empty Git repository and prepares the folder for version control. The Basic Save Workflow git add <file> -> git commit -m "Your message" This is the fundamental two-step process for saving changes. First, `git add` moves your changes to the staging area. Second, `git commit` takes a snapshot of the staged changes and saves it permanently to the repository's history with a descriptive message. Checking the Status git status This is your most-used command. It tells you which files have been changed, which files are in the staging area, and if you have any untracked files. It's like a dashboard for your project.

4 more steps in this tutorial

Sign up free to access the complete tutorial with worked examples and practice.

Sign Up Free to Continue

Sample Practice Questions

Challenging
A developer modifies `fileA.js`, `fileB.js`, and creates a new file `fileC.js`. They want to create a single commit that only includes the changes to `fileA.js` and the new `fileC.js`. Which sequence of commands correctly accomplishes this?
A.git add fileA.js fileC.js git commit -m "Implement feature X"
B.git add . git commit -m "Implement feature X"
C.git add fileA.js git add fileC.js git commit fileA.js fileC.js
D.git commit -m "Implement feature X" git add fileA.js git add fileC.js
Challenging
Imagine Git did NOT have a staging area. You have made changes to 10 files related to two different tasks (e.g., 5 for a new feature, 5 for a bug fix). How would the absence of a staging area make it difficult to create two separate, clean commits for each task?
A.It would be impossible to save any changes at all.
B.You would be forced to save all 10 file changes in one large, unclear commit.
C.You would have to create 10 separate commits, one for each file.
D.The `git commit` command would not work without a staging area.
Challenging
A student runs `git add my_file.txt`, then immediately edits `my_file.txt` again to fix a typo they just noticed. Finally, they run `git commit -m "Add file"`. Which version of `my_file.txt` is saved in the commit?
A.The newest version, including the typo fix.
B.Neither version, because Git will detect a conflict.
C.The version that existed at the moment `git add` was run, WITHOUT the typo fix.
D.An empty file, because the file was modified after being added.

Want to practice and check your answers?

Sign up to access all questions with instant feedback, explanations, and progress tracking.

Start Practicing Free

More from III. Introduction to Version Control with Git

Ready to find your learning gaps?

Take a free diagnostic test and get a personalized learning plan in minutes.