So I just finished learning how to use Git and GitHub, and wow, it was a journey! A few weeks ago, I had no idea what version control even meant. Now I'm pushing code to GitHub like it's no big deal (okay, I still get a little excited every time it works ).
I wanted to write this guide while everything is still fresh in my mind because I remember how confusing it all seemed at first. If you're just starting out like I was, hopefully this helps!
Quick explanation of what these things are:
- Git = a tool that tracks all the changes you make to your code. It's like having unlimited undo buttons!
- GitHub = a website where you can store your code online and share it with others
That's literally all I knew when I started. Let's dive in!
What You Need
Just make sure you have:
- A computer (I'm on Windows but I'll try to cover Mac and Linux too)
- A GitHub account - go to github.com and sign up, it's free
- Don't worry if you're not super comfortable with the command line, I wasn't either
Step 1: Installing Git Bash
Okay, so first thing - I needed to install Git on my computer.
If You're on Windows (like me)
- I went to git-scm.com
- Clicked the big "Download for Windows" button
- Ran the installer (it's like installing any other program)
-
Here's the thing - there are a LOT of options during installation. I honestly just kept clicking "Next" with the default settings and everything worked fine
- One thing I made sure to check: "Git Bash Here" - this lets you right-click in any folder and open Git Bash there, super convenient!
Clicked through the rest and finished
If You're on Mac
I asked my friend who uses Mac and apparently Git might already be installed! Open Terminal and type:
git --version
If it's not there, Mac will ask if you want to install it. Pretty straightforward from what I understand.
If You're on Linux
My friend who uses Ubuntu told me to run:
sudo apt-get update
sudo apt-get install git
For other Linux versions, you might need different commands but I think the idea is the same.
Did It Work?
Open Git Bash (on Windows I just searched for "Git Bash" in the start menu) and type:
git --version
If you see something like git version 2.40.0, you're good! If not... uh... maybe try installing again?
Step 2: Connecting Git to GitHub
This part confused me at first but it's actually not too bad.
Tell Git Who You Are
Git needs to know your name and email so it can tag your work. I opened Git Bash and typed:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Obviously use YOUR actual name and email . And make sure the email matches whatever you used for GitHub!
To check if it worked:
git config --global --list
Setting Up SSH Keys (This Part Seemed Scary But Wasn't)
So apparently you need something called an SSH key to connect securely to GitHub. I watched a YouTube video to understand this better, but here's what I did:
Generate the key:
ssh-keygen -t ed25519 -C "your.email@example.com"
It asked me where to save it - I just hit Enter to use the default location.
Then it asked for a passphrase. I added one for security but you can just hit Enter twice to skip if you want.
Start something called the SSH agent:
eval "$(ssh-agent -s)"
I don't fully understand what this does but it needs to be running
Add the key:
ssh-add ~/.ssh/id_ed25519
Copy the key:
cat ~/.ssh/id_ed25519.pub
This spits out a bunch of random characters starting with ssh-ed25519. I copied THE WHOLE THING.
Put it on GitHub:
- Went to GitHub
- Clicked my profile picture in the top right → Settings
- Found "SSH and GPG keys" on the left side
- Clicked "New SSH key"
- Gave it a name (I called mine "My Laptop")
- Pasted that long string of characters
- Clicked "Add SSH key"
Test if it worked:
ssh -T git@github.com
I got a message saying "Hi [my username]! You've successfully authenticated" and I literally did a little celebration 🎉
Step 3: Understanding What Git Actually Does
Before I started using commands, I tried to understand WHY I needed this.
You know how you save files like:
my_code.pymy_code_v2.pymy_code_final.pymy_code_final_FINAL.pymy_code_final_FINAL_I_SWEAR.py
Yeah... Git makes this unnecessary. Instead, you keep one file and Git remembers every version you save. You can go back to ANY previous version whenever you want.
Words I Had to Learn
- Repository (or repo): Basically just a folder that Git is watching
- Commit: Saving a snapshot of your project at a moment in time
- Branch: Like a copy of your project where you can try stuff without breaking the original (I haven't really used this yet though)
- Remote: Your project stored online on GitHub
Step 4: Making My First Repository
Okay here's where it got real. Time to actually USE Git!
Creating a Project
I made a new folder for my project:
mkdir my-first-project
cd my-first-project
Then I initialized Git (basically telling Git to start watching this folder):
git init
That's it! Git is now tracking this folder. There's a hidden .git folder created but you don't really need to touch it.
Checking the Status
I learned this command is super important:
git status
Use this ALL THE TIME. It tells you what's going on with your files.
Making a File
I created a simple README file:
echo "# My First Project" > README.md
Then checked status again:
git status
Git saw the file but said it was "untracked" - meaning Git noticed it but isn't saving its history yet.
Adding Files (Staging)
To tell Git to track the file:
git add README.md
Or if you want to add everything:
git add .
The . means "everything in this folder".
Checked status again:
git status
Now it said the file was "staged" and ready to commit.
My First Commit!
This is like taking a snapshot:
git commit -m "Add README file"
The -m part is for adding a message. ALWAYS add a message explaining what you did! Future you will thank you.
Good messages:
- "Add login feature"
- "Fix typo in homepage"
- "Update installation steps"
Bad messages:
- "update"
- "fixed stuff"
- "asdfjkl"
Viewing History
To see all your commits:
git log
Or for a cleaner version:
git log --oneline
Pretty cool seeing your project history like this!
Step 5: Putting My Code on GitHub!
This was the part I was most excited about - making my code visible online!
Creating a GitHub Repository
- Went to GitHub
- Clicked the "+" button in the top right
- Clicked "New repository"
- Named it
my-first-project(same as my local folder) - Did NOT check "Initialize with README" because I already have one
- Clicked "Create repository"
Connecting Everything
GitHub showed me some commands. I copied the SSH URL (the one starting with git@github.com).
Then I ran:
git remote add origin git@github.com:YOUR_USERNAME/my-first-project.git
The word "origin" is just a nickname for this GitHub repository.
Double-checked it worked:
git remote -v
Pushing My Code Online
This was the moment of truth:
git branch -M main
git push -u origin main
What these commands do:
-
git branch -M main- names your main branch "main" -
git push -u origin main- sends your code to GitHub and remembers this as the default place to push
I refreshed GitHub and SAW MY CODE ONLINE. I'm not gonna lie, I genuinely did a dance because of how excited I was.
Step 6: The Daily Workflow
Now that everything was set up, here's what I do when I'm actually coding:
1. Make some changes to my files
echo "Learning Git is easier than I thought!" >> README.md
2. Check what changed
git status
Or see the actual differences:
git diff
This shows you exactly what lines changed. Super useful!
3. Add and commit
git add .
git commit -m "Add my thoughts to README"
4. Push to GitHub
git push
Since I set up the default earlier, I can just type git push now.
Step 7: Getting Changes FROM GitHub
This is important if you're working on multiple computers or with other people.
I Tested This By Editing on GitHub
- Went to my repository on GitHub
- Clicked on README.md
- Clicked the pencil icon to edit
- Added a line: "This was edited directly on GitHub!"
- Scrolled down and clicked "Commit changes"
Pulling Those Changes
Back in Git Bash:
git pull
Checked my file:
cat README.md
And there was the line I added on GitHub! Magic!
Step 8: Commands I Use All The Time
I literally keep this list open in a notepad:
# Starting stuff
git init # Start tracking a folder
git clone <url> # Download someone else's repository
# Daily workflow
git status # What's changed?
git add . # Stage everything
git commit -m "message" # Save a snapshot
git push # Send to GitHub
git pull # Get changes from GitHub
# Checking things
git log --oneline # See commit history
git diff # What changed?
# When I mess up
git restore <file> # Undo changes to a file
git restore --staged <file> # Unstage a file
Step 9: Mistakes I Made (So You Don't Have To)
Mistake #1: Forgot to pull before pushing
I got an error saying my push was rejected. Turns out someone else had pushed changes. Solution: Always git pull before git push!
Mistake #2: Terrible commit messages
My first few commits were like "updated file" and "changes". Now I can't remember what I did! Write clear messages!
Mistake #3: Added sensitive files
I almost committed a file with my API key in it . Use .gitignore files to tell Git to ignore certain files.
Mistake #4: Panicked when I saw a merge conflict
These happen when Git can't automatically combine changes. It's scary at first but not the end of the world. Git marks the conflicts in your files and you just need to choose which version to keep.
What I'm Learning Next
Now that I've got the basics down, I want to learn:
- How to use branches properly (I keep hearing about them)
- What pull requests are and how to do code reviews
- More advanced Git commands
- How to contribute to open source projects
Git was intimidating at first. The commands felt weird, and I didn't understand why I needed all this complexity just to save my code.
Start small. Make a repository. Practice the basic commands: add, commit, push, pull. Don't worry about advanced stuff yet. I've been using Git for a few weeks and I still only use like 5 commands regularly!
You've got this! And hey, if I figured it out, anyone can
Top comments (0)