What is Git?
Git is a version control system.
π In simple words: Git is used to save the history of changes in a project, like a βsave gameβ in a video game.
Simple analogy
Imagine you are writing a paper in Word:
-
Version 1
-
Version 2
-
Final version
-
Final FINAL version π
Git does this automatically, but:
-
Saves every change
-
Lets you go back
-
Lets you work as a team without stepping on each other
-
Works perfectly with code
π§ Why is Git so important?
Learning Git lets you:
-
Never lose your work
-
Work with other people
-
Try ideas without breaking anything
-
Work like a professional programmer
π‘ ALL tech companies use Git.
π§© Key concepts (very important)
Before using any commands, you need to understand these key concepts:
1οΈβ£ Repository (repo)
Itβs the project.
π¦ Think of a repository as:
A special folder that Git controls
It can contain:
-
Code
-
Images
-
Documentation
-
Any file
2οΈβ£ File
These are normal files:
-
.html -
.css -
.js -
.txt
Git watches these files and detects changes.
3οΈβ£ Version / Commit
A commit is a snapshot of the project at a point in time.
πΈ Every commit:
-
Has a message (βwhat I didβ)
-
Has a date
-
Has an author
Example of commit message:
Add login button
4οΈβ£ History
Git saves every commit in order.
This lets you:
-
See what changed
-
Go back to a previous version
-
Know who did what
π§° Installing Git
On Windows
Download from: π https://git-scm.com
Install it with default options.
On macOS
brew install git
On Linux
sudo apt install git
Verify it is installed:
git --version
π Getting started with Git (first steps)
Step 1: Create a project
Create a folder:
my-project
Enter the folder:
cd my-project
Step 2: Initialize Git
Inside the folder:
git init
π This creates a Git repository.
π‘ Git now controls this folder.
π Git status (very important)
You can always ask:
git status
This tells you:
-
Which files changed
-
What is ready to save
-
What is not
π Create your first file
Create a file called:
hello.txt
Content:
Hi, this is my first project with Git
Check status:
git status
You will see something like:
new untracked file
β Adding files (staging)
Git works in 3 areas:
1οΈβ£ Working Directory
Your normal files
2οΈβ£ Staging Area
Files ready to be saved
3οΈβ£ Repository
Saved files (commits)
To move a file to staging:
git add hello.txt
Or all of them:
git add .
πΎ Save changes (commit)
Now save the changes:
git commit -m "Add hello.txt file"
π First commit done!
π Basic Git workflow (memorize it)
This is the most important Git workflow:
Edit β git add β git commit
It is always like that.
π§ͺ Modify a file
Edit hello.txt:
Hello world
I am learning Git
Check status:
git status
Add and save:
git add .
git commit -m "Update greeting message"
βͺ Go back in time
See history:
git log
You will see a list of commits.
Each commit has an ID.
To go back to a commit:
git checkout COMMIT_ID
β οΈ This is read-only mode (not for working).
πΏ Branches
What is a branch?
A branch is a parallel line of work.
π± It lets you:
-
Try ideas
-
Not break the main project
The main branch is called:
main
Create a branch
git branch new-feature
Switch to it:
git checkout new-feature
Or in a single step:
git checkout -b new-feature
Merge branches
Go back to main:
git checkout main
Merge:
git merge new-feature
π Git vs GitHub (very important)
π« Git is NOT GitHub
| Git | GitHub |
|---|---|
| Local tool | Online platform |
| Version control | Repository host |
| Works offline | Requires internet |
GitHub uses Git, but they are not the same.
βοΈ Upload a project to GitHub (basics)
-
Create a repository on GitHub
-
Connect the local repository:
git remote add origin URL
- Push the code:
git push -u origin main
π₯ Download a project
git clone REPO_URL
β οΈ Common mistakes
β Not committing often β Bad commit messages β Working without branches β Not using git status
π§ What to learn next
Once you master this:
-
.gitignore -
Merge conflicts
-
Rebase
-
GitHub Flow
-
Pull Requests
π Final recap
Git lets you:
-
Save versions
-
Go back
-
Work as a team
-
Code professionally
Key workflow:
git status
git add .
git commit -m "clear message"