Git Tutorial With Examples: Master Version Control Step By Step

Logan Jul 13, 2026

Welcome to this comprehensive guide on Git, designed to help you understand and effectively use this powerful distributed version control system. Whether you're new to Git or looking to expand your skills, this tutorial will provide a solid foundation and practical examples to get started with.

Git Workflow
Git Workflow

Git is an essential tool for modern developers, enabling multiple people to work together on a single project without overwriting each other's changes. By the end of this tutorial, you'll have a clear understanding of how to initialize a Git repository, stage changes, commit updates, and manage branches - all while working collaboratively with others.

how git works info sheet
how git works info sheet

Getting Started with Git

Before we dive into the core functionalities, let's ensure Git is installed on your system. You can check this by opening your terminal or command prompt and typing:

GIT CHEAT SHEET
GIT CHEAT SHEET

git --version

Installing Git

Git & GitHub Cheat Sheet 🔥 | Commands, Workflow, Branching & Version Control (Beginner to Pro)
Git & GitHub Cheat Sheet 🔥 | Commands, Workflow, Branching & Version Control (Beginner to Pro)

If Git is not installed, visit the official download page and follow the instructions for your operating system. Once installed, verify the installation again using the previously mentioned command.

Pro tip: To make the Git experience more delightful, consider using a Graphical User Interface (GUI) like Git GUI or SourceTree.

Initializing a Git Repository

What is Git? (Day 1 Beginner Guide)
What is Git? (Day 1 Beginner Guide)

After installing Git, it's time to initialize your first repository. Create a new folder for your project and navigate into it using the terminal (or command prompt).

Inside this folder, initialize a new Git repository with the following command:

git init

Git & GitHub Roadmap for Beginners
Git & GitHub Roadmap for Beginners

Adding and Committing Changes

Now that you have a Git repository, add a new file (e.g., README.md) and input some content. To stage this change for commit, use:

GitHub Complete Beginner Guide (2026) | Learn Git & GitHub Step-by-Step
GitHub Complete Beginner Guide (2026) | Learn Git & GitHub Step-by-Step
git log Explained (Day 8 Git Guide)
git log Explained (Day 8 Git Guide)
Git & GitHub Explained for Beginners (2026)
Git & GitHub Explained for Beginners (2026)
the gitpops workflow diagram shows how to use it for presentations and presentation
the gitpops workflow diagram shows how to use it for presentations and presentation
git diff Explained (Day 9 Git Guide)
git diff Explained (Day 9 Git Guide)
Beginner’s Guide to Getting Started with GitHub in 2025 – Easy Step-by-Step Tutorial
Beginner’s Guide to Getting Started with GitHub in 2025 – Easy Step-by-Step Tutorial
Master Git Fast: 2-Hour Step-by-Step Cheat Sheet
Master Git Fast: 2-Hour Step-by-Step Cheat Sheet
Git Cheat Sheet: Essential Commands and Tips
Git Cheat Sheet: Essential Commands and Tips
Introduction to Git & Version Control | Beginner's Guide
Introduction to Git & Version Control | Beginner's Guide
Git Branching Explained in 60 Seconds
Git Branching Explained in 60 Seconds
the diagram shows how git works
the diagram shows how git works
GIT Commands: Your Essential Skills Guide 🚀
GIT Commands: Your Essential Skills Guide 🚀
Git Workflow Roadmap
Git Workflow Roadmap
a white paper with writing on it and an image of git's versus glittab
a white paper with writing on it and an image of git's versus glittab
Git commands Cheat Sheet
Git commands Cheat Sheet
Git for Beginners: Version Control Every Developer Needs
Git for Beginners: Version Control Every Developer Needs
the git workflow is shown in purple and red, with instructions on how to use it
the git workflow is shown in purple and red, with instructions on how to use it
a diagram showing how to use the git workflow for your website or application
a diagram showing how to use the git workflow for your website or application
Git & GitHub Basics for Beginners
Git & GitHub Basics for Beginners
Git Commands Every Beginner Developer Should Know (Save This Cheat Sheet)
Git Commands Every Beginner Developer Should Know (Save This Cheat Sheet)

git add README.md

Pro tip: The 'add' command only stages changes. To see the status of your working directory and staging area, use git status.

After staging your changes, commit them with a meaningful message:

git commit -m "Add README file with project description"

Note that the '-m' flag allows you to include a commit message directly into the command line.

Branching and Merging

Branches allow teams to collaborate effectively by working on isolated features or fixes without affecting the main project. To create a new branch, use:

git checkout -b new-branch

In this command, '-b' automatically creates the new branch if it doesn't exist, then switches you to it. You can verify that you're on the correct branch by checking the current branch name in the bottom-left corner of your terminal (if you're using a GUI) or by using git branch --show-current.

Merging Changes

Once you're done with your changes in the new branch, switch back to the main branch (often 'main' or 'master') with:

git checkout main

Next, merge your changes into the main branch using:

git merge new-branch

In case of a merge conflict (when Git doesn't know how to handle differences between branches), Git will pause the process, and you'll need to resolve the conflicts manually before committing the merge.

Fetching and Pulling Changes

To fetch changes from a remote repository (e.g., one hosted on GitHub), use:

git fetch origin

Then, to incorporate those changes into your local repository, use:

git pull

Pro tip: Combining 'fetch' and 'merge' (or 'rebase') commands, 'git pull' automatically incorporates changes from a remote repository into your local repository.

And there you have it - a comprehensive overview of Git with practical examples! You're now well-equipped to start your collaborative coding journey or expand your existing Git skills. Ready to take the next step? Explore advanced Git concepts like rebasing, tagging, or even contributing to open-source projects on GitHub.