Git and GitHub Basics – Tracking and Sharing Your Code - 5 | 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.

Introduction to Git

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

Today, let's discuss Git. How would you describe Git in your own words?

Student 1
Student 1

It sounds like a tool for managing changes in code?

Teacher
Teacher

Exactly! Git is a version control system. It helps you track changes to files, revert back to previous versions, and collaborate with others safely.

Student 2
Student 2

So, it's like a time machine for code?

Teacher
Teacher

Yes! That's a great way to think about it. Without Git, you might end up with filenames like project-final-final-2.html, which can get confusing!

Getting Started with Git

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

Now let's move on to installing Git. Can anyone tell me where we can download Git?

Student 3
Student 3

From the official Git website?

Teacher
Teacher

Correct! You can download Git from the official site. After installation, how will we confirm that Git is installed?

Student 4
Student 4

By running 'git --version' in the command line?

Teacher
Teacher

Right again! It's crucial to know your version of Git once installed.

Understanding GitHub

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

GitHub serves a different purpose than Git. What do you think that is?

Student 1
Student 1

Is it like a social media platform for code?

Teacher
Teacher

That's an interesting way to put it! GitHub is a platform where you can store your Git repositories online, collaborate with others, and share your code.

Student 2
Student 2

Can we use Git without GitHub?

Teacher
Teacher

Yes, you can use Git without GitHub, but GitHub cannot function without Git!

Basic Git Commands

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

Let's talk about some basic Git commands. What is the command to create a new Git repository?

Student 3
Student 3

It’s 'git init'!

Teacher
Teacher

Exactly! And once we want to track changes, what command would we use?

Student 4
Student 4

'git add' to stage the files?

Teacher
Teacher

Right! And to save the changes permanently, we commit using 'git commit -m'. Remembering these commands will make version control much easier!

Connecting Git with GitHub

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

To connect our local repo to GitHub, we first create a new repository on GitHub. What should we do next?

Student 1
Student 1

We connect it using 'git remote add origin' and the repository URL?

Teacher
Teacher

Exactly! Then, to push our local changes to GitHub, we use 'git push -u origin main'. What do you think happens when we do that?

Student 2
Student 2

Our code becomes live on GitHub!

Teacher
Teacher

Right! Great job today; you've learned the basics of Git and GitHub!

Introduction & Overview

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

Quick Overview

This chapter introduces Git and GitHub, outlining their roles in tracking code changes and facilitating collaboration.

Standard

In this chapter, you will learn about Git as a version control system for tracking changes to your code, GitHub as the cloud platform for hosting repositories, and the essentials of using Git commands to manage your projects effectively.

Detailed

Git and GitHub Basics – Tracking and Sharing Your Code

In this chapter, you'll learn the fundamental concepts behind Git and GitHub, two crucial tools for developers. Git is a version control system that enables you to track changes to your files, revert to previous versions, and collaborate with other developers safely by recording every modification made to your codebase. Think of Git as your code's 'Time Machine'. Without Git, organizing multiple iterations of your files can become chaotic, such as saving versions named 'project-final-final-2.html'. With Git, you can easily switch between different versions of your project.

GitHub complements Git by providing a platform to store your repositories online, making collaboration easier and allowing you to share your code with others. You can use Git without GitHub, but GitHub relies on Git to function.

The chapter covers how to install and configure Git, creating a repository, tracking changes, viewing your commit history, and connecting your local repository to GitHub. Mastering these basic commands will prepare you to navigate software development processes efficiently.

Youtube Videos

Learn to Push Your Code to GitHub in 10 Minutes (Beginner Video) 🔥
Learn to Push Your Code to GitHub in 10 Minutes (Beginner Video) 🔥

Audio Book

Dive deep into the subject with an immersive audiobook experience.

What is Git?

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Git is a version control system. It helps you:
● Track changes to your files
● Go back to previous versions
● Work on new features without breaking the original code
● Collaborate with others safely

Think of Git like a “Time Machine” for your code.

Without Git:
● You might save multiple copies like project-final-final-2.html
With Git:
● Every version is recorded and you can switch between them easily.

Detailed Explanation

Git is a tool that allows developers to manage their code over time. It keeps track of every change made to the code, similar to how a time machine would let you travel back to previous moments. For instance, if you made an update to your work and then decided you didn't like it, Git lets you revert back to an earlier version without hassle. It also helps multiple people work on the same project simultaneously by keeping track of each person's changes.

Examples & Analogies

Imagine you’re writing a book. First, you write a chapter, but then you realize it needs revision. Instead of rewriting the whole chapter, you can go back to the original draft. Git does this for your coding projects—allowing you to view old drafts of your work whenever you need them.

What is GitHub?

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

GitHub is a website (a cloud service) that allows you to:
● Store your Git repositories online
● Collaborate with other developers
● Share your code with the world

Git is the tool. GitHub is the platform where you host your code online.

💡 Git can be used without GitHub, but GitHub cannot work without Git.

Detailed Explanation

GitHub complements Git by providing a platform where developers can store their repositories online. It enhances collaboration by allowing developers to share their code and work together efficiently. While you can use Git on your local machine without GitHub, it’s more common to use Git in tandem with GitHub to facilitate sharing and teamwork.

Examples & Analogies

Think of Git as a toolkit you use to work on your car, whereas GitHub is a parking garage where you can safely store your car. You can fix and improve your car (code) using your toolkit (Git), but if you want to show it to friends or work on it with others, you park it in the garage (GitHub).

Installing Git

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

To use Git on your computer:
🔹 Step 1: Download Git
Go to the official Git website (search: Download Git). Choose your OS (Windows/Mac/Linux) and follow the setup instructions.
🔹 Step 2: Check Git Installation
Open your terminal or command prompt and run git --version
If Git is installed, it will show a version like:
git version 2.40.1.

Detailed Explanation

To start using Git, the first step is to install it on your computer. You can download Git from its official website. Choose the right version for your operating system, whether it’s Windows, Mac, or Linux. After installation, you can verify that Git has been installed correctly by typing git --version in your terminal, which will display the version number of Git that is currently installed.

Examples & Analogies

Installing Git is like setting up a new app on your phone. First, you go to the app store to download it. Once installed, you usually need to check if it’s working by opening it. Just as you would look for the app icon on your phone, you check the version of Git to make sure it's set up correctly.

Basic Git Setup (First Time Only)

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Before using Git, set your identity:
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
This information will be attached to your commits (changes).

Detailed Explanation

When you use Git for the first time, you need to set up your identity so that your name and email are associated with your code changes (commits). This is important because when you collaborate on projects, it will show who made which changes. You do this by entering commands in the terminal that configure your username and email address.

Examples & Analogies

Think of this setup like signing a school project. When you turn in a project, you put your name on it so everyone knows it was your work. Setting up your identity in Git does the same thing—it identifies you as the author of the code changes.

Creating a Git Repository

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

A Git repository is like a folder with version control.
🔹 Step 1: Create a folder
mkdir my-first-project
cd my-first-project
🔹 Step 2: Initialize Git
git init
You’ll see:
Initialized empty Git repository in [your folder]
Git is now watching this folder!

Detailed Explanation

To start a new project with Git, first, you need a repository, which is a directory that Git manages. You create a folder for your project and then initialize Git in that folder with a command. This sets up Git to track changes in that folder, and you’ll see a confirmation message indicating that the Git repository has been created.

Examples & Analogies

Creating a Git repository is like starting a new notebook for a school subject. You create the notebook (folder) and then open it (initialize Git) so that you can start writing your notes (code) in it, knowing everything you write will be organized and easily retrievable.

Tracking Changes

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

🔹 Step 1: Create a file
echo "Hello World" > index.html
🔹 Step 2: Check status
git status
You’ll see the file is untracked (Git knows it exists but hasn’t saved it yet).
🔹 Step 3: Add the file to Git
git add index.html
Now Git is staging the file (ready to save).
🔹 Step 4: Commit (save the file)
git commit -m "Added index.html"
🟢 Your file is now saved with a message. This message helps track what the change was.

Detailed Explanation

Once you create a file, you need to tell Git that this file exists and that you want it to track its changes. First, you check the status of the repository to see which files are untracked. Then, you 'add' the file to Git, which stages it for saving. Finally, you 'commit' the file, which not only saves the current state of the file, but also requires you to write a message that describes what you've done.

Examples & Analogies

Think of this process like writing a paper for school. You start by writing a draft (creating a file), then you check what parts of your draft are complete (checking status). Once you’ve reviewed it, you make sure the draft is ready for submission (adding it), and finally, you submit it with a title page summary of what your paper is about (committing with a message).

Making and Saving More Changes

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Edit index.html:
`<!DOCTYPE html>

Welcome!

Step 1: Check what's changedgit statusStep 2: Add changesgit add index.htmlStep 3: Commit againgit commit -m "Updated homepage with h1"`
Each commit is a snapshot of your project.

Detailed Explanation

After you’ve made changes to a file, you need to follow a similar process as before. You check the status to see what’s changed, stage those changes, and then commit them with a message that summarizes what you’ve done. Each commit represents a snapshot of your work at that point in time, allowing you to track the evolution of your project.

Examples & Analogies

Imagine you're revising an essay. After making changes to the text (editing the file), you read through it once more to see what you’ve altered (checking status). After ensuring everything looks good, you make it ready for a final submission (adding changes), and then you submit the updated version with a note explaining the added sections (committing with a message).

Viewing History

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

See all your past commits:
git log
Sample output:
commit 9a3c1234b...
Author: Your Name
Date: Today’s date
Message: Updated homepage with h1

Detailed Explanation

You can look back at all the past changes made to your code by using the git log command. This generates a list of all the commits you have made, displaying information such as the unique commit ID, the author, the date, and the commit message. This allows you to review your project’s history and understand how it has changed over time.

Examples & Analogies

This is like keeping a journal of your daily activities. Each entry lists what you did that day (commits) along with the date and any special notes (commit messages). You can review past entries anytime you want to remember what you accomplished on previous days.

Connecting with GitHub

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Let’s push your local repository to GitHub.
🔹 Step 1: Create an account on GitHub
● Go to github.com and sign up.
🔹 Step 2: Create a new repository
● Click New Repository
● Give it a name like my-first-project
● Do not initialize with README (we already have files locally)
🔹 Step 3: Connect local repo to GitHub
In your terminal:
git remote add origin https://github.com/your-username/my-first-project.git
This tells Git where your online code is stored.
🔹 Step 4: Push your code to GitHub
git branch -M main
git push -u origin main
Now check your GitHub profile—your code is live on the internet!

Detailed Explanation

To share your code with others, you need to push your local repository to GitHub. This involves creating an account and setting up a new repository online. Once you have your repository, you connect it to your local repository with a command that specifies where your online code is stored. Finally, you push your changes to GitHub, making your code available on the internet.

Examples & Analogies

This process is like uploading a project to a shared drive after working on it on your computer. You first log into the shared drive (GitHub), then create a folder for your project (new repository), link your local files to that folder (connecting), and finally move your files to the shared drive (pushing). Once uploaded, everyone can see your work.

Summary of Common Git Commands

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Command Purpose
git init Start a new Git repo
git status Check file status
git add filename Stage changes
git commit -m "message" Save snapshot
git log View commit history
git remote add origin Link to GitHub URL
git push Upload to GitHub

Detailed Explanation

Understanding the basic commands in Git is crucial for effective usage. Each command serves a specific purpose: initializing a repository, checking the status of files, staging files for commit, committing changes, viewing commit history, linking the repository to GitHub, and finally pushing your changes to GitHub. Learning these commands will make you more proficient in using Git.

Examples & Analogies

Think of these commands as tools in a toolbox. Just like you would use different tools for different tasks (a hammer for nails versus a screwdriver for screws), you'll use different Git commands for various operations in the version control process. Familiarizing yourself with these tools will help you complete your projects more efficiently.

Definitions & Key Concepts

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

Key Concepts

  • Version Control: A system for managing changes to software, ensuring previous versions are retrievable.

  • Git: A tool that allows developers to track and manage their code versions.

  • GitHub: A platform that hosts Git repositories and facilitates collaboration.

Examples & Real-Life Applications

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

Examples

  • Using the command 'git init' to create a new repository.

  • After making edits to a file, using 'git add' to stage changes for commit.

Memory Aids

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

🎵 Rhymes Time

  • With Git, your code won't slip, just track and commit!

📖 Fascinating Stories

  • Imagine a librarian who keeps every version of every book. Git helps developers do just that with their code, maintaining a clear history.

🧠 Other Memory Gems

  • GIT: Grab It Temporarily - Add to your repository before saving snapshots.

🎯 Super Acronyms

GIT

  • Gain Insights Truly - Track your project's evolution.

Flash Cards

Review key concepts with flashcards.

Glossary of Terms

Review the Definitions for terms.

  • Term: Git

    Definition:

    A version control system for tracking changes in computer files.

  • Term: GitHub

    Definition:

    A cloud-based platform for hosting Git repositories and collaborative development.

  • Term: Repository

    Definition:

    A directory or storage space where your project files and version history are contained.

  • Term: Commit

    Definition:

    A snapshot of your project at a certain point in time, along with a message describing the changes.

  • Term: Version Control

    Definition:

    A system that records changes to files over time, allowing you to revert to specific versions.