Skip to main content

Day 5 topics

Updated 19 min readMarkdown

a name


1\. Quick revision of Python and OOP
2. Very simple database concept
3. Creating table and selecting data using SQLite
4. Linux terminal commands
5. Basic Vim commands
6. Git introduction
7. GitHub introduction
8. Git staging area
9. Git commit and snapshot
10. Basic Git workflow practice

Part 1: Quick Python Revision

Until now, we learned:

Variables
Data types
Conditionals
Loops
Functions
File handling
Exception handling
Dictionaries
OOP basics

In Python, we can store student data like this:

student = {
    "name": "Ram",
    "age": 18,
    "marks": 80
}

This works while the program is running.

But after the program is closed, this data is lost.

So we need a database.


Part 2: Little Bit of Database

What is a database?

A database is a place where we store data permanently in an organized way.

Example:

A school may store:

Student name
Age
Class
Marks
Address
Phone number

A database stores data in tables.


What is a table?

A table is like a register.

Example:

id name age marks
1 Ram 18 80
2 Sita 19 90

Here:

id, name, age, marks = columns
Ram and Sita data = rows

What is SQLite?

SQLite is a simple database.

It is good for beginners because:

It is simple.
It stores data in one file.
Python already supports it.
No extra installation is needed.

Example database file:

students.db

Part 3: Simple SQLite Code

For Day 5, we are not learning full CRUD.

We are only learning:

Create table
Insert simple data
Select/read data

Simple code

import sqlite3

connection = sqlite3.connect("students.db")
cursor = connection.cursor()

cursor.execute("""
CREATE TABLE IF NOT EXISTS students (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT,
    age INTEGER,
    marks REAL
)
""")

cursor.execute("""
INSERT INTO students (name, age, marks)
VALUES ('Ram', 18, 80)
""")

cursor.execute("SELECT * FROM students")

students = cursor.fetchall()

for student in students:
    print(student)

connection.commit()
connection.close()

Explanation

import sqlite3

This imports the SQLite database module.

connection = sqlite3.connect("students.db")

This connects Python to the database.

If students.db does not exist, Python creates it.

cursor = connection.cursor()

Cursor is used to run SQL commands.

CREATE TABLE IF NOT EXISTS students

This creates a table named students.

SELECT * FROM students

This reads all data from the students table.


Part 4: Now Main Topic: Git and GitHub

Before learning Git, students should understand one problem.

Imagine you are building a Python project.

Day 1:

print("Hello")

Day 2:

You add a menu.

Day 3:

You add student management.

Day 4:

You add database.

Day 5:

Something breaks.

Now the problem is:

Which file changed?
When did it change?
What was working before?
Can we go back to old code?
How can multiple students work on the same project?

This is where Git helps.


Part 5: What is Git?

Git is a version control system.

Simple meaning:

Git tracks changes in our project.

It remembers the history of our code.

With Git, we can see:

What changed
When it changed
Who changed it
Why it changed
Previous versions of the project

Simple definition for students

Git is a tool that helps us save different versions of our project properly.

Instead of doing this:

project-final
project-final-new
project-final-latest
project-final-real
project-final-last

We use Git.

Git manages versions professionally.


Part 6: Why is Git Important?

Git is important because it helps us:

Track code changes
Save project history
Go back to old versions
Work safely on new features
Work in teams
Upload code to GitHub
Avoid losing code

Real-life example

Suppose you are working on a student management system.

Your project is working properly.

Then you try to add a database.

After adding the database, the project stops working.

Without Git:

You may not know what went wrong.
You may not know which file changed.
You may have to rewrite code again.

With Git:

You can check previous versions.
You can compare changes.
You can return to the working version.

Part 7: What is GitHub?

GitHub is a website/platform where we can store our Git projects online.

Simple meaning:

Git = tool on your computer
GitHub = website to store and share Git projects

Example:

Git tracks your project locally.
GitHub stores your project online.

Simple analogy

Git = camera
GitHub = online photo album

Git takes snapshots of your code.

GitHub stores those snapshots online.


Part 8: Git vs GitHub

Git GitHub
Installed on your computer Website/platform
Tracks code changes Stores code online
Works locally Works on the internet
Can be used without GitHub Needs Git project
Tool Hosting service

Simple line:

Git is the tool. GitHub is the place where we upload Git projects.


Part 9: Basic Linux Commands for Git

Before using Git, students should know basic terminal commands.

Check current folder

pwd

This shows where you are.


List files and folders

ls

Show hidden files also:

ls -a

Change folder

cd folder_name

Go back one folder:

cd ..

Go to home folder:

cd ~

Create folder

mkdir my_project

Create file

touch app.py

Clear terminal

clear

Remove file

rm app.py

Remove folder

rm -r my_project

Be careful with rm.


Show file content

cat app.py

Run Python file

python3 app.py

or:

python app.py

Part 10: Basic Vim Commands

Sometimes Git may open Vim.

For example, when writing commit messages.

Students do not need to master Vim now.

They only need basic survival commands.


Open file in Vim

vim app.py

Insert mode

Press:

i

Now you can write.


Save and exit

Press:

Esc

Then type:

:wq

Then press Enter.


Exit without saving

Press:

Esc

Then type:

:q!

Then press Enter.


Save only

Press:

Esc

Then type:

:w

Part 11: Git Installation Check

To check if Git is installed:

git --version

Example output:

git version 2.39.0

If this shows a version, Git is installed.


Part 12: Git Configuration

Before using Git, we should set name and email.

git config --global user.name "Your Name"
git config --global user.email "your@email.com"

Example:

git config --global user.name "Ram Sharma"
git config --global user.email "ram@gmail.com"

To check configuration:

git config --list

Part 13: What is a Git Repository?

A Git repository means a project folder where Git is tracking changes.

To create a Git repository:

git init

Example:

mkdir student_project
cd student_project
git init

Now Git starts tracking this project.


What happens after git init?

Git creates a hidden folder named:

.git

This .git folder stores Git history and information.

To see it:

ls -a

You will see:

.git

Important:

Do not delete the .git folder unless you want to remove Git tracking from the project.


Part 14: Git Workflow

Git has three main areas:

1\. Working Directory
2. Staging Area
3. Repository

This is very important.


1. Working Directory

This is your normal project folder.

This is where you create and edit files.

Example:

app.py
main.py
students.db
README.md

When you change a file, the change first stays in the working directory.


2. Staging Area

The staging area is a preparation area.

Before saving changes permanently in Git history, we first add them to staging.

Command:

git add app.py

or:

git add .

3. Repository

The repository is where Git permanently saves the committed history.

Command:

git commit -m "message"

Example:

git commit -m "Add student management code"

Part 15: What is Git Staging?

Staging means choosing which changes should go into the next commit.

Imagine you changed three files:

app.py
database.py
notes.txt

But you only want to save app.py and database.py in one commit.

You can do:

git add app.py
git add database.py
git commit -m "Add database feature"

Now notes.txt is not included in that commit.

So staging gives control.


Simple classroom analogy

Imagine you are packing a school bag.

On the table, you have:

Math book
Science book
Copy
Pen
Lunch box
Football

You do not put everything into the bag.

You choose only what is needed.

That choosing step is like staging.

Table = working directory
Selected items = staging area
Packed bag = commit

Part 16: What is a Git Commit?

A commit is a saved version of your project.

When we commit, Git saves the staged changes into history.

Command:

git commit -m "Initial commit"

The message should explain what changed.

Good commit messages:

Add student model
Create database table
Fix login error
Update README file

Bad commit messages:

done
final
changes
abc
test

Part 17: What is a Snapshot in Git?

A snapshot is a saved picture of your project at a specific time.

When you commit, Git creates a snapshot.

Example:

Commit 1: Initial project
Commit 2: Add student management
Commit 3: Add database connection
Commit 4: Fix marks calculation

Each commit is like a photo of your project.

If something breaks later, you can check old snapshots.


Simple analogy

Imagine taking photos while building a house.

Photo 1:

Empty land

Photo 2:

Foundation completed

Photo 3:

Walls completed

Photo 4:

Roof completed

Git commit is like taking these photos of your code.


Part 18: Important Git Commands

1. Initialize Git

git init

Starts Git tracking in a folder.


2. Check status

git status

Shows current condition of files.

It tells:

Untracked files
Modified files
Staged files
Clean working tree

3. Add file to staging

git add app.py

Add all changes:

git add .

4. Commit changes

git commit -m "Initial commit"

This saves staged changes into Git history.


5. View commit history

git log

Short version:

git log --oneline

6. See changes

git diff

This shows what changed before staging.


7. See staged changes

git diff --staged

This shows what is already staged.


Part 19: First Git Practice

Ask students to do this step by step.

Step 1: Create project folder

mkdir git_practice
cd git_practice

Step 2: Initialize Git

git init

Step 3: Create Python file

touch app.py

Step 4: Write Python code

Open file:

vim app.py

Press:

i

Write:

print("Hello Git")

Save and exit:

Esc
:wq

Step 5: Check status

git status

Git will show app.py as untracked.

Untracked means:

Git sees the file, but Git is not tracking it yet.

Step 6: Add to staging

git add app.py

Now check status again:

git status

Now the file is staged.


Step 7: Commit

git commit -m "Create first Python file"

Now Git has saved the first snapshot.


Step 8: Check history

git log --oneline

You will see your commit.


Part 20: Second Git Practice

Now edit app.py.

vim app.py

Change code to:

print("Hello Git")
print("This is my second line")

Save and exit.

Now check status:

git status

Git will show that app.py is modified.


See what changed

git diff

This shows the new line added.


Stage and commit again

git add app.py
git commit -m "Add second print message"

Now check history:

git log --oneline

You will see two commits.


Part 21: Understanding File States in Git

A file in Git can have different states.

1. Untracked

Git sees the file but is not tracking it.

Example:

touch notes.txt
git status

notes.txt will be untracked.


2. Modified

Git is already tracking the file, but you changed it.

Example:

vim app.py
git status

Now app.py may show as modified.


3. Staged

The file is ready to be committed.

Example:

git add app.py
git status

Now it is staged.


4. Committed

The file is saved in Git history.

Example:

git commit -m "Update app"

Now it is committed.


Part 22: Simple Git Flow Diagram

Working Directory
      |
      | git add
      v
Staging Area
      |
      | git commit
      v
Repository / Git History

Example:

Write code
↓
git status
↓
git add .
↓
git status
↓
git commit -m "message"
↓
git log --oneline

Part 23: What is GitHub Account?

GitHub is an online platform.

To use GitHub, students need:

GitHub account
Repository on GitHub
Git installed locally
Internet connection

GitHub helps us:

Upload projects
Share projects
Collaborate with team
Show portfolio
Submit assignments
Work with companies

Part 24: What is a Remote Repository?

A remote repository is a Git repository stored online.

Example:

Local repository = project on your laptop
Remote repository = project on GitHub

To connect local project with GitHub, we use:

git remote add origin repository_url

Example:

git remote add origin https://github.com/username/project-name.git

Part 25: Push and Pull

Push

Push means sending local commits to GitHub.

git push

Simple meaning:

Laptop to GitHub

Pull

Pull means bringing latest code from GitHub to your laptop.

git pull

Simple meaning:

GitHub to laptop

Clone

Clone means downloading a GitHub project to your laptop.

git clone repository_url

Example:

git clone https://github.com/username/project-name.git

Part 26: First GitHub Upload Practice

Step 1: Create a repository on GitHub

Go to GitHub and create a new repository.

Example name:

git-practice

Do not add README from GitHub for now.


Step 2: Connect local project to GitHub

Inside your local project folder:

git remote add origin https://github.com/username/git-practice.git

Step 3: Rename branch to main

git branch -M main

Step 4: Push code

git push -u origin main

Now the code is uploaded to GitHub.


Part 27: Common GitHub Upload Flow

After the first upload, the regular flow is:

git status
git add .
git commit -m "Your message"
git push

This is the most common Git workflow.

Students should memorize this flow.


Part 28: README File

A README.md file explains the project.

Create README:

touch README.md

Write:

# Student Management System

This is a simple Python project.

## Features

- Add student
- View student
- Learn Git and GitHub

Then:

git add README.md
git commit -m "Add README file"
git push

Part 29: What is .gitignore?

.gitignore tells Git which files not to track.

Example:

We may not want to track:

__pycache__
.env
database files
temporary files

Create .gitignore:

touch .gitignore

Example content:

__pycache__/
*.pyc
.env

Then commit it:

git add .gitignore
git commit -m "Add gitignore file"

Part 30: Important Git Terms

Repository

A Git-tracked project.

Commit

A saved version of the project.

Staging

Preparing selected changes for commit.

Snapshot

A saved picture of project state at a point in time.

Remote

Online Git repository, usually on GitHub.

Push

Send local commits to GitHub.

Pull

Bring latest changes from GitHub to local computer.

Clone

Download a GitHub repository.

Branch

A separate line of development.

Branches can be covered more deeply on Day 6.


Part 31: Common Mistakes Students Make

Mistake 1: Forgetting git add

Wrong:

git commit -m "Update code"

If files are not staged, commit may not include changes.

Correct:

git add .
git commit -m "Update code"

Mistake 2: Bad commit messages

Bad:

git commit -m "done"

Good:

git commit -m "Add student database table"

Mistake 3: Using GitHub without committing

Students may think code goes to GitHub automatically.

It does not.

Correct flow:

git add .
git commit -m "message"
git push

Mistake 4: Confusing Git and GitHub

Remember:

Git is local.
GitHub is online.

Part 32: Class Activity

Give students this task:

Task: Create and upload a simple Python project

Requirements

Create a folder:

student_git_project

Create a file:

app.py

Write:

print("Student Management System")

name = input("Enter student name: ")
age = input("Enter student age: ")

print("Name:", name)
print("Age:", age)

Then use Git:

git init
git status
git add app.py
git commit -m "Create student input program"

Create README.md:

# Student Git Project

This is a simple Python project for learning Git and GitHub.

Then:

git add README.md
git commit -m "Add README"

Finally upload to GitHub:

git remote add origin https://github.com/username/student_git_project.git
git branch -M main
git push -u origin main

Part 33: Teacher Explanation Script

You can explain like this:

"Until now, we wrote Python code and saved files normally. But in real projects, simply saving files is not enough. We need to track changes. We need to know what changed, when it changed, and how to go back if something breaks. Git helps us manage the history of our project. GitHub helps us store that project online and share it with others."

Then say:

"Git works in three steps. First, we write code in the working directory. Second, we stage the changes using git add. Third, we save the changes using git commit. A commit is like a snapshot of our project."


Part 34: Final Summary for Students

Today we learned:

Database stores data permanently.
SQLite is a simple database.
Git tracks code changes.
GitHub stores Git projects online.
Git and GitHub are different.
Git has working directory, staging area, and repository.
Staging means preparing changes before commit.
Commit means saving a snapshot.
Push means uploading to GitHub.
Pull means downloading latest changes from GitHub.
Clone means copying a GitHub project to local computer.

Day 5 Homework

Homework 1: Git practice

Create a new folder:

day5_homework

Create a Python file:

main.py

Write any simple Python program.

Then use:

git init
git add .
git commit -m "Initial homework commit"

Modify the file and commit again:

git add .
git commit -m "Update homework program"

Check history:

git log --oneline

Homework 2: GitHub practice

Upload the homework project to GitHub.

Commands:

git remote add origin your_repository_url
git branch -M main
git push -u origin main

Homework 3: Write answers

Students should write short answers:

1\. What is Git?
2. What is GitHub?
3. What is the difference between Git and GitHub?
4. What is staging?
5. What is a commit?
6. What is a snapshot?
7. What is push?
8. What is pull?
9. What is clone?
10. Why is Git important?

Best One-Line Explanation

Git helps us track project history, and GitHub helps us store and share that project online.

26 views

No comments yet. Be the first to comment.

Day 5 topics