The first time I heard of the term Git and saw a tutorial about it, I panicked and wondered, Umm, will I be able to maneuver this jargon?
The most common terms in the tutorial were:
- “Just pull first.”
- “Did you commit?”
- “Why did you push to the main???”
I followed through, trust you me with no idea of what was going on.
From a beginner on Git, maybe like you, and now to a guru, let's dive innit!
I will take you through Git, version control, push, pull, and tracking changes with a little fun and games to keep us sane.
What Is Git?
Imagine you are writing an assignment, and I am sure that at times, you have maybe saved files like this:
- _assignment.xlsx
- assignment_final.xlsx
- assignment_final_final.xlsx
- assignment_final_final_pleaseGod.xlsx_
Git comes in and say lo and behold, let me clear this mess
Git is a tool that keeps track of changes in your code over time.
It remembers:
- _What changed
- When it changed
- Who changed it_
And let's you go back in time, if things go wrong, you can get an idea. If you have used Excel Power Query, does it ring a bell, the tracking of changes?
Think of Git as Google Docs version history, but for code.
What Is Version Control?
Version control is just a tech guru's way of saying Let’s not dare to destroy our work.
It helps you:
- _Track changes
- Work with other people without fighting
- Undo mistakes without crying (bubbles kwa mapua lol)_
Without version control:
- Someone deletes code
- No one knows who did it
- Everyone pretends it wasn’t them_
With Git:
_Git knows.
Git always knows._
What is a repository (repo)?
The Project you are working on + Git = A Repository (Repo)
A folder that Git is watching very closely
To start watching a folder, you run:
git init
After running this, the folder is now under Git’s surveillance CCTV lol, and tracking Changes this is where we say Git is a snitch lol.
When you edit the project, Git notices but does nothing automatically.
You must tell Git: Yes, I meant to do that.
Step 1: Check What Changed with git status
git status
Git will politely say things like
- This file changed
- This file is untracked
- You are a mess, please commit
Step 2: Add Changes aka Staging
Before saving a snapshot(I will explain this shortly), you must stage files, stage file means choosing which changes you want Git to save.
Example:
Imagine you’re moving houses. Your room is full of things. You don’t want to move everything. You put only selected items into boxes. Those boxes = staging area. Only what’s in the box goes on the truck.
We do this by using:
git add
This tells Git, I approve these changes. Another analogy under this is, think of it like packing items before traveling.
If you don’t pack it, it doesn’t go on the trip.
Step 3: Commit Changes, aka Take a Snapshot
A snapshot here refers to a saved picture of your project at a specific moment in time. Please note not a photo photo but a record of all the files, their content, exactly how they looked at that moment. Now you save the changeson git bash using git commit -m "Added login feature"
A commit refers to a snapshot(the photo we said is not a photo) of your project with a message explaining what you did
Good commit message:
Fixed button alignment
Bad commit message:
_stuff
final
pls work_
Git remembers this forever. Choose wisely.
Push: Sending Your Code to the Internet
So far, everything lives on your computer.
To send your code to GitHub / GitLab / Bitbucket (aka the cloud), you push on gitbash using git push
In other words this means Here world, take my code.
This means that:
_Your code is backed up
Your teammates can see it
Your mistakes are public _
Pull: Getting Code from the Internet
If someone else updated the project, you need to pull their changes, and we do this using git pull
In other words this means we are telling git give me the latest version.
Please Note:
Always pull before you start working, unless you enjoy:
_Merge conflicts
Panic
Questioning your career choices
Working With Other Humans (Collaboration)_
When multiple people work on one project:
_Everyone pulls the latest code
Everyone makes changes
Everyone commits
Everyone pushes_
If two people change the same line:
Git pauses
Looks at both of you
Git says solve it yourselves.
This is called a merge conflict, basically Git saying I refuse to choose sides.
Everyone pretends Git is easy.
It’s not, at first.
But one day you’ll type:
_git push_
And feel powerful.
Until it fails.
Then you’ll Google.
Like the rest of us.
And with that, I recall that after my first tutorial, I didn't get the difference between Git and Version Control, and here is the difference: version control is the concept of tracking changes over time, while Git is a tool that helps you do version control in real life.
Welcome to Git.
You’re officially a tech babe/ dude now.
Top comments (0)