Free Online Course · Self-paced · Hands-on

Git & GitHub Tutorial for Beginners (with examples)

Free Git and GitHub tutorial with hands-on examples tested on Git 2.52: commits, branches, merge and rebase, remotes, undo, and history cleanup.

  • 14 chapters
  • 69 lessons
  • ~12h
  • Beginner to Intermediate
  • Tested with Git 2.52.0
  • Updated Sep 2026
Git & GitHub Tutorial for Beginners (with examples)
By Last updated

About this course

This free course starts with git init in an empty directory and ends with rewriting history on a shared repository. In between it covers the everyday workflow, branching, merge and rebase, remotes on GitHub and GitLab, and every level of undo. Command behaviour follows the official Git documentation for current releases, and the lessons use the newer git switch and git restore commands alongside the older git checkout you will still see in other guides.

Every lesson was run on a real repository, and the output you see is what Git printed on a RHEL 10.2 host with Git 2.52. The undo chapter is organised by how far a mistake has travelled: still in the working tree, staged, committed locally, or already pushed. That is the question you need to answer before picking restore, reset, or revert.

If you are new to version control, work through the chapters in order. If you already commit and push every day, go straight to the Undoing Changes chapter, the merge and rebase chapter, or Troubleshooting Common Errors, and keep the Git cheat sheet open for the flags.

What you'll learn

  • Configure Git, create or clone a repository, and make your first commits
  • Inspect changes with git diff and git show, and write commit messages reviewers can follow
  • Create, switch, rename, and delete branches with git switch and git branch
  • Merge and rebase branches, resolve conflicts, and pick the right one for each situation
  • Work with remotes, set upstream branches, and fetch, pull, and push safely with --force-with-lease
  • Undo mistakes at every level, from unstaging a file to reverting a commit that is already public
  • Recover lost work with git reflog and read HEAD~, HEAD^, and detached HEAD states
  • Stash work in progress, squash commits, and remove large files from history with git-filter-repo

Who this course is for

  • Developers who use Git through an IDE button every day and want to know what the commands underneath actually do
  • New team members who need branch, pull, and push habits that do not break a shared repository
  • DevOps and platform engineers who clean up history, shrink repositories, or move projects between GitHub and GitLab
  • Sysadmins who keep scripts, configuration, or playbooks under version control

Prerequisites

  • Comfortable on the command line, including cd, ls, mkdir, and editing a file in a terminal editor
  • Git 2.23 or later on Linux, macOS, or Windows with Git Bash, because the lessons use git switch and git restore
  • A free GitHub or GitLab account for the remote, SSH, and VS Code chapters. No paid plan is needed

Versions and testing environment

Every command in this course was run on this stack

ComponentVersionNotes
Git 2.52.0 Used for most lessons on the RHEL 10.2 lab host
Red Hat Enterprise Linux 10.2 Lab host for the command examples. The commands are the same on macOS and in Git Bash on Windows
git-filter-repo 2.47.0 Used in the history-rewrite and repository-move lessons in place of git filter-branch
Git on Ubuntu 2.53.0 Ubuntu 26.04 LTS, used for the git show lesson

Syllabus

14 chapters · 69 lessons · ~12h of reading

  1. 1 Getting Started with Git 4 lessons · ~28 min
    1. Part 1 Getting started with GitHub 7 min read
    2. Part 2 git init - create your first repository 8 min read
    3. Part 3 Configure Git globally (user.name, user.email, aliases) 5 min read
    4. Part 4 Clone an existing repository 8 min read
  2. 2 The Basic Workflow - Add, Commit, Inspect 5 lessons · ~41 min
    1. Part 5 The standard Git workflow explained 6 min read
    2. Part 6 git diff - see what changed 9 min read
    3. Part 7 Write good Git commit messages 8 min read
    4. Part 8 git commit --amend - fix the last commit 9 min read
    5. Part 9 git show - inspect any commit 9 min read
  3. 3 Branching and Switching 6 lessons · ~55 min
    1. Part 10 git branch - create and manage branches 14 min read
    2. Part 11 List all local and remote branches 8 min read
    3. Part 12 git checkout - switch branches (legacy way) 8 min read
    4. Part 13 git switch - the modern branch switcher 7 min read
    5. Part 14 Rename a Git branch 11 min read
    6. Part 15 Delete a Git branch (local and remote) 7 min read
  4. 4 Merging, Rebasing and Conflict Resolution 5 lessons · ~46 min
    1. Part 16 git merge - integrate two branches 8 min read
    2. Part 17 git merge vs git rebase - when to use which 9 min read
    3. Part 18 git rebase - replay commits onto a new base 14 min read
    4. Part 19 git cherry-pick - pick a single commit 7 min read
    5. Part 20 Fix "pulling is not possible - unmerged files" 8 min read
  5. 5 Working with Remote Repositories 12 lessons · ~1h 29m
    1. Part 21 git remote add - link to a remote 5 min read
    2. Part 22 git remote set-url - change the remote URL 10 min read
    3. Part 23 Remove a remote from your repository 9 min read
    4. Part 24 Set the upstream branch (git push -u) 8 min read
    5. Part 25 git fetch - download without merging 9 min read
    6. Part 26 git fetch vs git pull - the real difference 5 min read
    7. Part 27 git pull - fetch and merge in one step 7 min read
    8. Part 28 git pull --rebase - cleaner history 5 min read
    9. Part 29 Force pull from remote (overwrite local) 5 min read
    10. Part 30 git push - upload your commits 11 min read
    11. Part 31 git push --force-with-lease (safe force push) 8 min read
    12. Part 32 Check out a remote branch 7 min read
  6. 6 Tags and Releases 1 lesson · ~7 min
    1. Part 33 git tag - create, list, push, and delete tags 7 min read
  7. 7 Undoing Changes (every level of undo) 11 lessons · ~2h
    1. Part 34 Undo git add (unstage a file) 7 min read
    2. Part 35 Unstage multiple files at once 10 min read
    3. Part 36 git restore - the modern restore command 9 min read
    4. Part 37 Discard uncommitted changes in working tree 9 min read
    5. Part 38 git reset - soft, mixed, and hard explained 11 min read
    6. Part 39 git revert - undo a public commit safely 16 min read
    7. Part 40 Revert your repo to a previous commit 11 min read
    8. Part 41 Remove a commit from history 17 min read
    9. Part 42 Change an old commit message 15 min read
    10. Part 43 git clean - remove untracked files 8 min read
    11. Part 44 Remove untracked files from working directory 7 min read
  8. 8 History and Inspection 4 lessons · ~44 min
    1. Part 45 git blame - find who changed a line 16 min read
    2. Part 46 git reflog - recover lost commits 14 min read
    3. Part 47 HEAD~, HEAD^, HEAD@{n} - reference syntax 6 min read
    4. Part 48 Detached HEAD state - what it means and how to fix it 8 min read
  9. 9 File Management in Git 5 lessons · ~43 min
    1. Part 49 git rm - remove a tracked file 9 min read
    2. Part 50 Rename a file or directory in Git 7 min read
    3. Part 51 Delete a file or directory from Git 8 min read
    4. Part 52 Untrack a file without deleting it 11 min read
    5. Part 53 .gitignore - patterns and examples 8 min read
  10. 10 Advanced Operations 6 lessons · ~53 min
    1. Part 54 git stash - save work-in-progress 7 min read
    2. Part 55 Squash commits into one 9 min read
    3. Part 56 git prune - clean up unreachable objects 8 min read
    4. Part 57 Reduce repo size with git filter-branch 16 min read
    5. Part 58 Move content between Git repositories 13 min read
    6. Part 59 Migrate from GitHub to GitLab Coming soon
  11. 11 GitHub Integration (VS Code, SSH) 3 lessons · ~23 min
    1. Part 60 Set up GitHub with VS Code 7 min read
    2. Part 61 VS Code Remote SSH for GitHub 7 min read
    3. Part 62 Delete a repository on GitHub 9 min read
  12. 12 GitLab Workflows 2 lessons · ~16 min
    1. Part 63 GitLab tutorial for beginners 9 min read
    2. Part 64 Set up GitLab with VS Code 7 min read
  13. 13 Troubleshooting Common Errors 4 lessons · ~45 min
    1. Part 65 Fix: fatal: couldn't find remote ref main 9 min read
    2. Part 66 Fix: fatal: Could not read from remote repository 15 min read
    3. Part 67 Fix: cannot open .git/FETCH_HEAD - Permission denied 13 min read
    4. Part 68 Fix: cannot delete branch checked out at 8 min read
  14. 14 Reference / Cheat Sheet 1 lesson · ~13 min
    1. Part 69 The complete Git command cheat sheet 13 min read

Hands-on labs

6 guided builds you run yourself

  1. Resolve a real merge conflict

    Merge two branches that changed the same lines, read the conflict markers, and complete the merge commit.

  2. Rebase a feature branch onto main

    Rebase onto the latest origin/main, resolve conflicts partway through, and undo the whole rebase when it goes wrong.

  3. Recover lost commits with reflog

    Bring back work after a hard reset, an amend, a deleted branch, and a rebase using git reflog entries.

  4. Force push safely after rewriting history

    Use --force-with-lease, pinned to a known commit, so a rewritten branch cannot overwrite a teammate's push.

  5. Shrink a bloated repository

    Find the large blobs behind a slow clone, strip them from history with git-filter-repo, and publish the rewritten history.

  6. Move a directory to another repository with its history

    Filter the source repository down to one path and merge it into an existing target repository without losing commits.

Where to go after this course

  • Git Command Cheat SheetOne page of the commands from this course to keep open while you work.
  • Pro Git bookThe free book on git-scm.com, for internals such as objects, refs, and packfiles that this course only touches.
  • Terraform Associate courseIts CI/CD lesson runs plan and apply from GitHub Actions on the pull request workflow you practised here.
  • Ansible courseThe RHCE EX294 exam expects you to keep playbooks in Git and push them from VS Code.

Frequently Asked Questions

What is the difference between Git and GitHub?

Git is the version control program that runs on your machine. It records commits, branches, and history in the .git directory of your project and works with no network connection or account at all. GitHub, like GitLab, is a hosting service for Git repositories. It stores a remote copy and adds pull requests, code review, issues, and CI on top. You can learn most of Git without an account and add a remote when you need to share work.

Which Git version should I install?

The current Git release is 2.55.0, published on 29 June 2026, and Git for Windows 2.55.0 is the current Windows build. Linux distributions usually ship an older release, such as 2.52.0 on RHEL 10.2, and that is fine for everything in this course. The only hard requirement here is Git 2.23 or later, which added git switch and git restore. Run git --version to check what you have, and see the Git downloads page for current installers.

Does Git work the same on Windows, macOS, and Linux?

The commands and options are the same on all three. Git for Windows includes Git Bash, so the shell examples in this course work there as written. The main difference is line endings: Windows uses CRLF and Linux and macOS use LF, and the core.autocrlf setting controls how Git converts them. Set it once when you install Git so mixed teams do not see whole files change in every diff.

Is it safe to rewrite history I have already pushed?

Only when you coordinate with everyone who has pulled that branch. For a shared branch such as main, use git revert, which adds a new commit that undoes the old one and leaves history intact. On your own feature branch, rebasing, amending, or squashing and then pushing with --force-with-lease is normal. Rewrites that touch the whole repository, such as removing a large file with git-filter-repo, change every later commit ID, so everyone has to re-clone afterwards.

How long does it take to learn Git?

You can learn commit, branch, pull, and push in a day or two. Being comfortable with rebase, conflict resolution, and recovering from mistakes takes a few weeks of daily use on a real project. The fastest way to get there is to break a practice repository on purpose and recover it with git reflog.

Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with 15+ years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels across development, DevOps, networking, and security, delivering robust and efficient solutions for diverse projects.

  • Go (programming language)
  • Python (programming language)
  • DevOps
  • Computer Security
  • Cloud Computing
  • Kubernetes
  • Linux
  • Ansible (software)