Git for Beginners: The Ultimate Tutorial to Learn Git (2025)

Learn Git from the ground up! This beginner-friendly Git tutorial shows you step-by-step how to install Git, create your first repository, make commits, and work with GitHub.

Git for Beginners: The Ultimate Tutorial to Learn Git (2025) hero image

Does this sound familiar? You’re working on an important project, and your folder explodes with file versions like project_final.docx, project_final_v2.docx, and project_REALLY_final_revised.docx. This chaos is not only confusing but also carries the risk of losing important changes.

This is where Git comes in. Git is the professional tool that ends this chaos and forms the foundation of modern software development and efficient collaboration. But don’t worry, it’s not just for developers! Anyone who needs to manage versions of files can benefit from Git.

In this introduction to Git, we’ll guide you step-by-step from installation to your first real project. No prior knowledge is needed. By the end of this tutorial, you’ll be able to manage your own projects with Git. Let’s get started!

What is Git and Why is it so Powerful?

Git is a Distributed Version Control System (DVCS). That sounds complicated, but at its core, it means two simple yet revolutionary things:

  1. Version Control: Git logs every single change in your project. Think of it as a time machine for your code. You can revert to a previous state at any time, compare changes, and see exactly who changed what, and when.
  2. Distributed: Everyone working on the project has a full copy of the entire project history on their own computer. This makes Git incredibly fast and allows you to be productive even without an internet connection.

The core idea of Git is that it doesn’t just store individual file changes; it saves complete snapshots of your entire project at a specific point in time.

Step 1: Installing and Configuring Git

Before we can begin, Git needs to be installed on your system.

Installing Git

Open your browser and go to the official Git website: git-scm.com/downloads. Download the appropriate version for your operating system (Windows, macOS, or Linux) and follow the installer’s instructions.

INFO

During installation, select the “Git Bash Here” option to easily use Git from the Explorer. “Visual Studio Code” is a great choice for the default editor if you have it installed. For most other steps, you can stick with the default settings.

Verifying the Installation

After installation, open your terminal (or Git Bash on Windows) and enter the following Git command:

git --version

If a version number like git version 2.42.0 appears, everything worked. Congratulations, your first Git tutorial has begun!

Telling Git Who You Are

Every change you save (a “commit”) is tagged with your name and email address. You only need to do this configuration once per system.

# Set your username
git config --global user.name "Your Name"

# Set your email address
git config --global user.email "your@email.com"

You can verify that your name was saved correctly with git config --global user.name.

Step 2: Your First Git Repository – The Basic Workflow

A repository (or repo for short) is simply a project folder managed by Git.

Creating the Repository

Create a new folder for your project and navigate into it using your terminal.

# Create a new folder
mkdir my-first-git-project

# Change into the folder
cd my-first-git-project

Now for the magic command to turn this folder into a Git repository:

git init

Git has now created a hidden subfolder named .git. This is where Git stores all its magic. The most important rule: Never touch this folder manually!

The Git Workflow: Understanding the Staging Area

To truly master the basics of Git, we need to understand the three “areas” where your files can be:

  1. Working Directory: Your normal project folder where you edit your files.
  2. Staging Area (Index): A waiting area. Here, you gather all the changes you want to save in your next snapshot. This allows you to craft your commits precisely.
  3. Repository (.git folder): The final, secure archive. Everything committed here is permanently saved.

The cycle is always: Modify -> Stage -> Commit.

Interaktiver Git-Workflow

1. Arbeitsverzeichnis

2. Staging Area

3. Repository (Commits)

The Most Important Commands in Action

Let’s create our first file, hello.txt:

echo "Hello World from Git" > hello.txt

Your best friend when working with Git is the git status command. It always shows you the current state:

git status

Git now reports an untracked file. To start tracking this file, we use git add:

git add hello.txt

The file is now in the staging area. git status will now show it under “Changes to be committed”. Time for our first commit:

git commit -m "Create initial version of hello.txt"

A git commit saves the current state of the staging area as a new snapshot. The -m option allows you to provide a message directly.

Now, let’s make a change and see the difference:

echo "Git is helpful" >> hello.txt
git diff

The git diff command shows you exactly what has changed (+ for added lines, - for removed lines). To save this change, we repeat the cycle:

git add hello.txt
git commit -m "Add a second line to hello.txt"

To view the entire history of your project, use git log:

git log --oneline

The --oneline option provides a compact view.

Step 3: Branches – Experiment and Develop Safely

Imagine your project as a tree. The main branch is the stable trunk. A branch is like a new limb sprouting from that trunk, where you can work without disturbing the main version. This is perfect for developing features in isolation.

Creating and Using a New Branch

# Create a new branch named "feature/expand-text"
git branch feature/expand-text

# Switch to the new branch
git checkout feature/expand-text

TIP

You can create and switch to a new branch in one go with git checkout -b feature/expand-text! The modern alternative is git switch -c feature/expand-text.

All commits you make now will be on this new branch, leaving the main branch untouched.

Merging Changes

When your feature is complete, you’ll want to merge the changes back into the main trunk.

# Switch back to the main branch
git checkout main

# Merge the changes from the feature branch into main
git merge feature/expand-text

In most simple cases, this works seamlessly. git merge combines the histories of the two branches.

Cleaning Up

After a successful merge, you can delete the now-unneeded feature branch:

git branch -d feature/expand-text

Step 4: Collaborating with GitHub & Remote Repositories

So far, your project only exists as a local repository on your computer. That’s great for personal projects, but what if you want to:

  • Have a backup of your work in a secure, remote location?
  • Collaborate with other developers?
  • Showcase your code to the world?

This is where a remote repository comes in. Think of it as a copy of your project on a server on the internet. The most well-known and largest platform for this is GitHub.

Your First Repository on GitHub

Connecting your local repository to a repository on GitHub is a crucial step.

  1. Create an Account: If you haven’t already, create a free account at GitHub.com.

  2. Create a New Repository: On GitHub, click “New repository”. Give your project a name, but leave it empty for now (no README, .gitignore, or license).

  3. Copy the URL: GitHub will show you the URL of your new, empty repository. Copy it.

  4. Add the Remote in Your Local Repository: Go back to your terminal and run the following Git command to establish the connection:

    git remote add origin YOUR_GITHUB_URL

    origin is the default name for your main remote repository.

Pushing and Pulling Changes

Now that the connection is established, you can work with these three important Git commands:

  • git push: Uploads your local commits to the remote server.

    # The very first time, you need to tell Git where the 'main' branch should go.
    git push -u origin main

    After this initial push, a simple git push is all you’ll need.

  • git pull: Downloads the latest changes from the server and integrates them into your project.

  • git clone: Clones an existing repository from GitHub to your computer.

    git clone YOUR_GITHUB_URL

Self-Hosted Git Servers

If you don’t want to use GitHub, there are self-hosted alternatives. Examples include Gitea or Forgejo. These offer similar functionality to GitHub but are installed on your own server.

Step 5: The Visual Way – Git in VS Code

The command line is powerful, but not everyone’s favorite. Visual Studio Code has fantastic Git integration that makes your life easier.

  • Source Control Panel: In the left sidebar, you’ll see all your changes.
  • Stage with a Click: The + icon next to a file adds it to the staging area.
  • Commit: Type your message at the top and click the checkmark.
  • Push & Pull: Use the “Sync Changes” button at the bottom to sync your changes with the remote repository.
  • Extensions like “GitGraph” visualize your branch structure, making your history easy to understand.

Conclusion: You’ve Mastered the Basics!

Congratulations! You’ve just learned the foundations of Git. You now know how to use a version control system to manage your projects, save changes securely, and even collaborate with others via platforms like GitHub.

These key commands are now in your toolkit: git init, git add, git commit, git status, git log, git branch, git checkout, git merge, git push, git pull, and git clone.

The best way to learn Git is through practice. Start a small project and experiment with these commands. Over time, using Git will become second nature.

FAQs

What's the difference between Git and GitHub?

Git is the actual version control system—software that runs on your computer and manages your project's history. GitHub is a web platform that hosts Git repositories. Think of it this way: Git is the tool (like a text editor), and GitHub is the place where you store and share the projects you create with that tool (like a cloud platform for documents).

I made a mistake. How can I undo a commit?

There are several ways to undo changes. A safe method is `git revert HEAD`. This command creates a new commit that undoes the changes of the last commit without altering the project history. Another, more powerful method is `git reset`, which should be used with caution as it rewrites history. For beginners, `revert` is often the better choice.

Why should I use 'main' instead of 'master' as the main branch?

Historically, 'master' was the default name. In recent years, the community has adopted 'main' as a more inclusive and neutral term. GitHub and many other platforms now use 'main' as the new default for every new repository. Functionally, there is no difference—it's purely a convention, but one that is becoming standard.

What's the difference between `git fetch` and `git pull`?

Both commands retrieve new data from a remote repository. However, `git fetch` only downloads the new changes without modifying your current working directory. You can then review what's new before integrating it. `git pull` is essentially a combination of `git fetch` and `git merge`. It downloads the changes AND immediately tries to merge them with your current branch. For beginners, `git pull` is often simpler, but `fetch` gives you more control.

How can I safely delete a local or remote branch?

You delete a local branch that has already been merged into `main` with `git branch -d branch-name`. Git will prevent deletion if there are unmerged changes. To delete a branch on GitHub (or another remote), you use `git push origin --delete branch-name`. Be especially careful with this if other team members might still need the branch.

Share this post:

This website uses cookies. These are necessary for the functionality of the website. You can find more information in the privacy policy