1. This article tackles:
- What is Version Control
- How Git Tracks Changes
- How to Push and Pull code
1.1 What is Version Control
For instance say you write an essay and there are different versions, e.g., Final_doc_1.docx, final_doc_2.docx. This can quickly become messy.
When it comes to GIT, Version control solves this by automatically tracking and updating changes without saving two different versions. Git helps in:
- Saving each change Automatically
- Letting one go back to previous versions
- Seeing who changed any part of the document and when.
1.1.1 Saving each change Automatically
This is done through:
git add .
git commit -m "saved changes"
1.1.2 Letting one go back to previous versions
To see previous versions of commit, one can view through:
git log
This displays the log of the commit, giving the commit Id, name of the author and the Date of the commit. For instance:
commit: abc3wef
Author: Robert
Date: Mon Jan 15 10:30:00 2026
Therefore, in order to go back to a specific version of the commit, we use:
git checkout <commit-id>
Moreover, when one wants to get the most recent version of the commit, we use the more general version:
git checkout main
1.1.3 Showing who changed what and when
Showing who changed what and when is done using the code:
git log --oneline
This displays a short, easy-to-read summary of your project’s commit history.
Next, to see what was changed the command:
git show
is used to display all the exact changes done to the files.
Last, but not least, the code:
git blame filename.txt
is used to show line by line history of the changes made(who changed each line)
1.2 How Git Tracks Changes
Git does not automatically save every change you make. Instead, it tracks changes using three simple stages. Understanding these stages is the key to using Git correctly.
The Three Stages of Git
1.2.1 Working Directory
This is where you edit your files.
- You write code
- You delete or modify files
- Git notices the changes but does not save them yet
To check changes, one uses:
git status
Git gives you a clear summary of what’s happening in your repository.
Example output:
On branch main
Changes not staged for commit:
modified: index.html
Untracked files:
script.js
1.2.3 Staging area
This is where you tell Git the changes you want to save. This is done through:
git add .
Basically, you are preparing Git for a commit and telling Git the changes you wish to keep.
1.2.4 Repository (Commit History)
This is where Git saves the staged files Once you commit. The commit is done by:
git commit -m "New files added"
Once this is done, the committed staged files are now permanently saved in Git's history.
Git knows what has changed by comparing the last commit with the current files. This can be displayed in Git using the code:
git diff
This displays the added or removed lines, or any modified code.
In simple terms, think of Git like a camera, where the Working Directory is the scene you are setting up in order to capture a picture, Staging Area is what you frame in the photo and Commit is the photo you save.
1.3 How to Push and Pull Code in Git
Basically, when one is working with Git the code you are writing exists in two places Local repository(your computer) and Remote Repository (GitHub). Essentially, pushing and pulling keeps these two locations in sync.
1.3.1 What is push ?
When you are done committing any changes on a file, pushing basically saves the files into the Remote Repository(GitHub). This is done by using the code:
git push
In short, this is like uploading your saved work.
1.3.2 What does "Pull" mean?
Pull basically downloads the saved files from the Remote Repository into your Local Repository(into your computer). This is done if you are occasionally collaborating and others may have committed changes in the last version you interacted with.
This is done using the code:
git pull
In short, this is like downloading updates. If you don't pull first before pushing Git may block your push or You may see a merge conflict. That’s why pulling first is a good habit.
Fun twist: The name Git comes from British slang meaning “someone who is stubborn”—which is fitting, because Git never forgets your changes.
Top comments (0)