Learn Git by Examples
2.43.0Git is a distributed version control system that tracks changes in any set of computer files, usually used for coordinating work among programmers collaboratively developing source code during software development.
Learn the essential Git commands for version control, from initializing repositories and cloning projects to inspecting commit history. These examples cover the fundamental workflows needed for effective code management and collaboration.
Repository Initialization
Learn how to start a new Git repository using the git init command. This example explains what happens under the hood when you initialize a project and how to prepare your directory for version control.
Cloning Repositories
Learn how to copy an existing Git repository to your local machine using git clone. This example demonstrates how to download a project, including its entire history and branches, to start collaborating.
Commit History
Learn how to view and navigate the history of your project using git log. This example covers viewing commit details, authors, dates, and messages to understand how your code has evolved.
Branch Creation
Learn how to create new branches in Git to isolate your work. This example covers creating branches with git branch and the modern git switch command.
Branch Switching
Learn how to navigate between different branches in your repository. This example compares the classic git checkout command with the modern git switch command.
Merge Conflicts
Learn how to identify and resolve merge conflicts in Git. This example shows what conflict markers look like and the steps to manually fix conflicting code.
Fast-Forward Merge
Understand the simplest type of merge in Git. A fast-forward merge happens when the target branch has not diverged from the source branch, allowing Git to simply move the pointer forward.
Three-Way Merge
Learn how Git handles divergent history using a three-way merge. This process creates a new merge commit to tie together two independent lines of development.
Staging Changes
Master the concept of the staging area (index) in Git. Learn how to use git add to selectively prepare files for your next commit.
Unstaging Changes
Learn how to remove files from the staging area without losing your work. This example covers the modern git restore command and the classic git reset command.
Discarding Changes
Learn how to permanently discard local changes to files. This example covers reverting files to their last committed state using git restore and git checkout.
Stash Listing
Learn how to view and manage your stashed changes. This example explains the stash stack, how to list entries, and how to inspect the contents of a specific stash.
Stash Apply
Learn how to reapply stashed changes to your working directory without removing them from the stash list. This is useful for applying the same changes to multiple branches.
Stash Pop
Learn how to apply stashed changes and immediately remove them from the stash list. This is the most common way to retrieve your work and clean up.
Push Changes
Learn how to upload your local commits to a remote repository. This example covers pushing branches, setting upstream tracking, and understanding the push process.
Pull Changes
Learn how to download and integrate changes from a remote repository. This example explains how git pull combines fetching and merging to keep your code up to date.
Fetch Updates
Learn how to safely download changes from a remote repository without merging them. This example explains the difference between git fetch and git pull.
Tag Creation
Learn how to mark specific points in your project history using tags. This example covers both lightweight tags and annotated tags for release management.
Tag Listing
Learn how to view and filter the tags in your repository. This example covers listing all tags, searching with wildcards, and viewing tag messages.
Tag Deletion
Learn how to remove tags from both your local repository and the remote server. This is useful for fixing mistakes or cleaning up old release candidates.
Commit Amend
Learn how to modify your most recent commit. This is perfect for fixing typos in commit messages or adding forgotten files without creating a new commit.
Reset Soft
Learn how to undo commits while keeping your changes staged. This is useful for squashing multiple commits into one or fixing a commit's content entirely.
Reset Mixed
Understand the default reset mode. Learn how to undo commits and unstage changes, keeping your work safe in the working directory for further editing.
Reset Hard
Learn how to destructively discard all local changes and revert your repository to a specific commit. This is a powerful command that should be used with caution.
Cherry-Pick Commits
Learn how to apply specific commits from one branch to another without merging the entire branch. This is useful for hotfixes and backporting changes.
Blame View
Learn how to inspect the history of a file line-by-line. Git blame helps you identify who changed what and when, providing context for debugging.
Diff View
Learn how to inspect changes in your repository. This example covers comparing working directory, staging area, commits, and branches.
Clean Untracked Files
Learn how to remove untracked files from your working directory. This is useful for cleaning up build artifacts, temporary files, or accidental creations.
Branch Deletion
Learn how to delete local and remote branches. This example covers safe deletion, forced deletion, and removing branches from the remote server.

