Git & GitHub for Beginners: The Complete Hands-On Guide

Messed up your code again? Want a time machine for your files? This guide walks you from zero to confident with Git basics, branching, and GitHub collaboration, step by step.

What You'll Learn

  • What Git is and why it matters.
  • How to track, save, and roll back code changes.
  • How to branch like a pro and avoid conflicts
  • How GitHub helps you collaborate and showcase your work.
  • Best Practices for version control.

Part 1: What is Git?



Git is a distributed version control system(DVCS) designed to track changes in source code during software development. Created by Linus Torvalds in 2005 (the same visionary behind Linux), Git revolutionized how developers manage projects by prioritizing speed, efficiency, and non-linear workflows. 

Key Characteristics of Git

  1. Version Control System (VCS)

    • Git records changes to files over time, allowing you to revisit specific versions later. Think of it as a "time machine" for your code.

    • Unlike saving files manually (e.g., project_v1.txtproject_v2.txt), Git stores snapshots of your entire project efficiently.

  2. Distributed Architecture

    • Every developer has a full copy of the project history locally, enabling offline work and reducing reliance on a central server.

    • Contrasts with centralized VCS (like SVN), where losing the server means losing history.

  3. Branching and Merging

    • Git’s lightweight branching lets you experiment with new features or fixes in isolated environments (branches) without disrupting the main codebase.

    • Merging branches is streamlined, making collaboration seamless.

  4. Integrity and Security

    • Git uses SHA-1 hashes to uniquely identify every change, ensuring data integrity. Any tampering is easily detectable.

Why Git?

  • Collaboration: Multiple developers can work on the same project simultaneously.

  • Accountability: Track who made changes and why (via commit messages).

  • Recovery: Revert to a stable state if bugs are introduced.

  • Open Source: Git is free, open-source, and the backbone of modern development.

Getting Started 

Before using Git, you'll need to install it and configure your identity.

  1. Install Git

    • Windows: Download from git-scm.com

    • Mac: Use Homebrew (brew install git) or download the installer

    • Linux: Use your package manager (e.g., sudo apt install git for Ubuntu)

  2. Verify Installation

    bash

    git --version

    (Should return e.g., git version 2.40.1)

  3. Configure Your Identity
    Git tracks who makes changes. Set your name and email (use the same email as your GitHub account):

    bash


    git config --global user.name "Your Name"
    git config --global user.email "your.email@example.com"
  4. View your config settings 

    bash


    git config --list

Your First Git Project

Let's create and track a to-do list project.
  1. Create a folder
    bash

    cd Desktop
    mkdir Git_and_Github_tutorial
    cd Git_and_Github_tutorial
  2. Initialize Git
    bash


    git init

        3. Create a file in your project folder

             I'll create a file named 'to-do.txt' and add to-do list items. 

bash
touch to-do.txt
nano to-do.txt
             Once inside nano, paste the following to-do list:
   txt
To-Do List
  • Do Git tutorial
  • Clean my desktop
  • Organize project folders
  • Review class notes
  • Write daily journal entry
  • Drink 2L of water
  • Go for a 30-minute walk
  • Read for 20 minutes
  • Respond to important emails
  • Backup important files to Google Drive
  • Plan tasks for tomorrow

    Then:

  • Press Ctrl + O to save the file

  • Press Enter to confirm the filename

  • Press Ctrl + X to exit nano

4. Check Status

    See which files are modified/staged:

bash
git status


5. Stage the file.

Before committing, add files to the staging area.

bash
git add to-do.txt # Stages a specific file OR
git add . # Stages all changed files

6. Commit your work.

Save a snapshot of your staged files with a descriptive message:

bash
git commit -m "Add initial to-do list"

7. View History
See a log of past commits.
bash
git log
Use q to exit the log view


Part 2: Branch Like a Pro
Want to try something new without breaking the main project? That’s where branching shines.

What is a Git Branch?

A branch is a separate workspace for experimenting, fixing bugs, or developing features independently without interfering with the main branch.


Branching Commands

1. Create a branch:

bash
git branch feature-login

2. Switch to it:

bash
git checkout feature-login

     or:

bash

git switch feature-login

3. Create & switch at once:

bash
git checkout -b edit-tasks

Try It Yourself

bash
git checkout -b edit-tasks
# Edit to-do.txt
git add .
git commit -m "Update task list with priorities"

Merging Back
Merging means combining the changes from one branch into another.

It’s how you bring your work together after working separately on different features or bug fixes.

bash
git switch main  # First, switch to the target branch
git merge edit-tasks

What If There’s a Conflict?

When changes overlap in the same file, Git pauses the merge and marks conflicts

Git marks conflict lines like:

bash
<<<<<<< HEAD
Old content
=======
New content
>>>>>>> edit-tasks

Fix the file manually → save → then:

bash
git add .
git commit  # Git provides a default merge message

Best Practices:

  • Always pull latest changes before merging

  • Keep branches short-lived to minimize conflicts

Clean Up Branches

Delete after merging:

bash
git branch -d edit-tasks

Force delete (unmerged):

bash
git branch -D edit-tasks

See All Branches

bash
git branch
git log --oneline --graph --all

Example workflow

git init
git add todo.txt
git commit -m "Create initial to-do list"
git branch edit-tasks
git switch edit-tasks
# ... edit files ...
git add .
git commit -m "Update task priorities"
git switch main
git merge edit-tasks

Real-World Workflow Example

  1. Start a new feature:

    bash
    git checkout -b feature-payment
  2. Make changes and commit:

    bash
    git add payment.js
    git commit -m "Add credit card processing"
  3. Sync with updated main:

    bash
    git switch main
    git pull origin main
    git switch feature-payment
    git rebase main # Or merge if preferred
  4. Finalize and merge:

    bash
    git switch main
    git merge feature-payment
    git push origin main
    git branch -d feature-payment

Part 3: Take It Global with GitHub



Time to upload your code, collaborate with others, and build your dev portfolio.

What is GitHub?

GitHub is a cloud-based platform built around Git, designed to host, manage, and collaborate on code repositories.

 While Git handles version control locally, GitHub extends its functionality by providing a centralized hub for teams and open-source projects.

Key Features of GitHub

1. Remote Repositories

  • Host Git repositories in the cloud (e.g., https://github.com/username/repo)

  • Sync local repositories with remote ones:

    bash

    git remote add origin https://github.com/username/repo.git
    git push -u origin main # Push local code to GitHub
  • Clone existing repositories:

    bash

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

2. Pull Requests (PRs)

  • Collaboration workflow: Propose changes from a branch and request reviews before merging into main.

  • Enables:

    • Code reviews

    • Automated checks (tests, linting via GitHub Actions)

    • Discussion threads on changes

3. Issues & Project Management

  • Track bugs, enhancements, and tasks with Issues (like a built-in ticketing system).

  • Organize work using:

    • Milestones (e.g., "Release v1.0")

    • Labels (e.g., "bug," "feature")

    • Projects (Kanban-style boards)

4. GitHub Actions (CI/CD)

  • Automate workflows (testing, deployments) with YAML configuration:

    yaml
    name: CI
    on: [push]
    jobs:
    build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: npm install && npm test

5. Additional Features

  • GitHub Pages: Host static websites (e.g., documentation, portfolios).

  • Discussions: Forum-like Q&A for repositories.

  • Codespaces: Cloud-based development environments.

Why Use GitHub?

  1. Collaboration: Streamline teamwork with PRs and reviews.

  2. Backup: Cloud storage for code (disaster recovery).

  3. Portfolio: Showcase projects to employers (your README.md is your resume!).

  4. Open Source: Contribute to projects (e.g., React, VS Code).

Getting Started with GitHub

1.  Create a Repo

    1. Go to GitHub
    2. Click + New Repository
    3. Fill in the name (e.g., todo-list)
    4. Choose whether to make the repository private or public.
    5. Click Create repository.











 

 

2. Link Local Repo

bash
git remote add origin https://github.com/your-username/todo-list.git
git push -u origin main  










Refresh your GitHub page to see the changes.















3. Clone a Repo
  
 bash
git clone https://github.com/username/repo.git
4. Pull Requests (PRs)

Use PRs to suggest changes and collaborate.

  1. Fork a repo

    - Navigate to the repository you want to fork and click on Fork


    Then click on Create Fork


      2. Clone it

      3. Create a branch

bash


git checkout -b fix-typo

     4. Push

bash


git push origin fix-typo

5. Go to GitHub → Click Pull Requests →New Pull request.

What’s Next?

  1. Practice – Start small. Create test projects. Get comfortable with branch, merge, and commit like it's second nature.
  2. Explore – Fork a cool open-source repo on GitHub. Try contributing a fix or improvement via a pull request.
  3. Level Up – Dig deeper into .gitignore, rebase, GitHub Pages, and GitHub Actions. Automation is your next frontier.
  4. Share Your Progress – Drop your GitHub profile link in the comments—let’s celebrate your journey!

Handy References

Your go-to tools when you're not sure what’s next:

That’s a Wrap 🎉

You now know how to:

✅ Track and save your code changes with Git ✅ Work safely in branches ✅ Collaborate like a pro on GitHub ✅ Push, pull, and merge with confidence

Keep exploring. Break things. Fix them. Repeat. That’s how devs grow.

Happy coding !— and may your merge conflicts be few

Comments

Popular posts from this blog

Getting Started with ROS2 Humble: Workspace, Packages, and Nodes

CREATING A PUBLISHER AND SUBSCRIBER NODES USING PYTHON

The Raspberry Pi