Back to Blog
Learning

๐Ÿ—‚๏ธ Getting Started with Git and GitHub: Your First Steps in Version Control

Nov 15, 2024
12 min read
๐Ÿ—‚๏ธ Getting Started with Git and GitHub: Your First Steps in Version Control

๐Ÿ—‚๏ธ Getting Started with Git and GitHub: Your First Steps in Version Control

When I first heard about Git, I thought it was this mysterious, complex tool that only "real" developers used. I was intimidated. I avoided it. I copied files manually and saved versions like "project-final-v2-FINAL-REALLY.txt".

Sound familiar?

Here's what I wish someone had told me: Git is just a way to save checkpoints of your work. That's it. Everything else builds from that simple concept.

Why Git Matters (Even for Beginners)

Before we dive into how Git works, let's talk about why it matters:

1. It's Everywhere

  • โ–นEvery professional developer uses Git
  • โ–นEvery company uses version control
  • โ–นEvery open-source project uses Git

If you want to work in tech, you'll use Git. Might as well learn it now.

2. It Saves You From Disaster

Ever accidentally deleted code? Or made changes that broke everything?

With Git, you can:

  • โ–นGo back to any previous version
  • โ–นSee what changed
  • โ–นUndo mistakes
  • โ–นNever lose your work

3. It Makes Collaboration Easy

Want to work with others? Want to contribute to open source? Want to show your code to potential employers?

Git makes all of this possible.

The Core Concept: What is Git?

Think of Git like a save system in a video game:

  • โ–นSave your progress = Commit
  • โ–นCreate a backup save = Branch
  • โ–นGo back to an old save = Checkout
  • โ–นShare your saves = Push to GitHub

That's it. Everything else is just details.

Installing Git

Windows:

  1. โ–นDownload from git-scm.com
  2. โ–นInstall with default settings
  3. โ–นOpen Git Bash or Command Prompt
  4. โ–นType git --version to verify

Mac:

# If you have Homebrew: brew install git # Or download from git-scm.com

Linux:

sudo apt-get install git # Ubuntu/Debian sudo yum install git # CentOS/RHEL

Your First Git Commands

Let's start with the absolute basics:

1. Initialize a Repository

# Navigate to your project folder cd my-project # Initialize Git git init

This creates a hidden .git folder that tracks your changes.

2. Check Status

git status

This shows you:

  • โ–นWhat files have changed
  • โ–นWhat files are ready to be saved
  • โ–นWhat branch you're on

3. Add Files

# Add a specific file git add filename.js # Add all files git add .

This tells Git: "Hey, I want to save these files."

4. Commit (Save Your Work)

git commit -m "Add login functionality"

This creates a checkpoint. The -m flag lets you add a message describing what changed.

5. See Your History

git log

This shows all your commits (saves). Press q to exit.

GitHub: Your Code's Home on the Internet

Git is the tool. GitHub is the website where you store your code.

Think of it like:

  • โ–นGit = Your local save system
  • โ–นGitHub = Cloud storage for your saves

Setting Up GitHub

  1. โ–นGo to github.com
  2. โ–นSign up for a free account
  3. โ–นCreate a new repository
  4. โ–นCopy the repository URL

Connecting Your Local Code to GitHub

# Add GitHub as a remote (like adding a cloud storage location) git remote add origin https://github.com/yourusername/your-repo.git # Push your code to GitHub git push -u origin main

Now your code is on GitHub! Anyone can see it (if it's public).

Essential Git Workflow

Here's the workflow you'll use 90% of the time:

1. Make Changes

Edit your files. Write code. Do your work.

2. Check What Changed

git status

3. Add Your Changes

git add .

4. Commit with a Message

git commit -m "Description of what you did"

Good commit messages:

  • โ–นโœ… "Add user authentication"
  • โ–นโœ… "Fix login bug"
  • โ–นโœ… "Update navbar styling"

Bad commit messages:

  • โ–นโŒ "Changes"
  • โ–นโŒ "Stuff"
  • โ–นโŒ "Fixed"

5. Push to GitHub

git push

That's it! Your code is saved and backed up.

Branches: Working on Different Features

Branches are like parallel universes for your code:

  • โ–นMain branch = Your stable, working code
  • โ–นFeature branch = Where you experiment

Creating a Branch

# Create and switch to a new branch git checkout -b feature-login

Switching Branches

# Go back to main git checkout main # Go to your feature branch git checkout feature-login

Merging Branches

# Switch to main git checkout main # Merge your feature branch git merge feature-login

Common Git Mistakes (And How to Fix Them)

"I committed to the wrong branch"

# Undo the commit (but keep your changes) git reset --soft HEAD~1 # Switch to the right branch git checkout correct-branch # Commit again git commit -m "Your message"

"I want to undo my last commit"

# Undo commit but keep changes git reset --soft HEAD~1 # Undo commit and discard changes (be careful!) git reset --hard HEAD~1

"I deleted a file by mistake"

# Restore from Git git checkout -- filename.js

"I made a typo in my commit message"

# Fix the last commit message git commit --amend -m "Correct message"

GitHub Collaboration Basics

Forking (Copying Someone's Project)

  1. โ–นClick "Fork" on any GitHub repository
  2. โ–นNow you have your own copy
  3. โ–นMake changes
  4. โ–นSubmit a Pull Request

Pull Requests (Asking to Merge Your Changes)

  1. โ–นMake changes on a branch
  2. โ–นPush to GitHub
  3. โ–นClick "New Pull Request"
  4. โ–นDescribe your changes
  5. โ–นWait for review

Cloning (Getting Someone's Code)

git clone https://github.com/username/repo.git

Your Learning Path

Week 1: Basics

  • โ–นโœ… Install Git
  • โ–นโœ… Create a GitHub account
  • โ–นโœ… Make your first commit
  • โ–นโœ… Push to GitHub

Week 2: Daily Workflow

  • โ–นโœ… Use git status regularly
  • โ–นโœ… Commit small changes often
  • โ–นโœ… Write good commit messages
  • โ–นโœ… Push daily

Week 3: Branches

  • โ–นโœ… Create branches for features
  • โ–นโœ… Switch between branches
  • โ–นโœ… Merge branches

Week 4: Collaboration

  • โ–นโœ… Fork a project
  • โ–นโœ… Clone repositories
  • โ–นโœ… Create pull requests

Tips for Success

1. Commit Often

Small, frequent commits are better than huge ones. Commit every time you:

  • โ–นAdd a feature
  • โ–นFix a bug
  • โ–นRefactor code
  • โ–นUpdate documentation

2. Write Good Commit Messages

Your future self will thank you. Be descriptive:

# Good git commit -m "Add user authentication with JWT tokens" # Bad git commit -m "Changes"

3. Don't Be Afraid to Experiment

Git is forgiving. You can always:

  • โ–นUndo commits
  • โ–นGo back in time
  • โ–นCreate branches
  • โ–นExperiment safely

4. Use .gitignore

Create a .gitignore file to exclude:

  • โ–นnode_modules/
  • โ–น.env files
  • โ–นBuild folders
  • โ–นOS files

5. Practice Daily

The more you use Git, the more natural it becomes. Use it for:

  • โ–นSchool projects
  • โ–นPersonal projects
  • โ–นTutorial code
  • โ–นEverything!

The Bottom Line

Git might seem complex, but it's just a way to:

  • โ–นSave your work
  • โ–นGo back in time
  • โ–นCollaborate with others
  • โ–นNever lose code

Start with the basics. Use it daily. Don't worry about advanced features yet. Before you know it, Git will feel as natural as saving a file.

Remember: Every expert developer was once a beginner who was confused by Git. You've got this! ๐Ÿš€

Now go create a GitHub account, make your first commit, and start building that portfolio. Your future self will thank you!

Back to BlogHome
// related

More in Learning

// Learning

๐Ÿ› ๏ธ Mistakes Are Your Teachers: Why Errors Are Actually Great

๐Ÿ› ๏ธ Error messages aren't your enemiesโ€”they're your teachers! Learn how to embrace mistakes, read error messages like a pro, and turn debugging into your superpower.

Dec 1, 2024
7 min read
โ–น Read article
// Learning

๐Ÿค AI as Your Coding Partner: Boosting Efficiency Without Losing Your Edge

๐Ÿค Learn how to use AI tools like ChatGPT and GitHub Copilot to accelerate your learning and productivity while maintaining your problem-solving skills and creativity. Real strategies for beginners.

Jan 5, 2025
11 min read
โ–น Read article
// Learning

๐Ÿ”Œ Understanding APIs: How Web Applications Talk to Each Other

๐Ÿ”Œ APIs might sound technical, but they're just ways for apps to communicate. Learn what APIs are, how they work, and how to use them in your projects with simple, practical examples.

Nov 10, 2024
10 min read
โ–น Read article