How Git Works (Step-by-Step)

πŸ“˜ Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.

✅ Some premium posts are free to read — no account needed. Follow me on Medium to stay updated and support my writing.

πŸŽ“ Top 10 Udemy Courses (Huge Discount): Explore My Udemy Courses — Learn through real-time, project-based development.

▶️ Subscribe to My YouTube Channel (172K+ subscribers): Java Guides on YouTube

Hey there, and welcome!

In this guide, we’re going to talk about Git — what it is, why it's so popular, and how it works behind the scenes.

If you’ve ever worked on a coding project and wanted a safe, organized way to track your changes or collaborate with others, Git is your best friend.

How Git Works

Let’s break it down — step by step — so it’s easy to follow, even if you're just getting started.


What Is Git and Why Use It?

So, what exactly is Git?

Git is a version control system. That means it keeps track of every change you make to your code, like a timeline you can rewind or fast-forward.

It’s kind of like having unlimited undo — but smarter. Git helps you go back to previous versions, experiment with new features safely, and work as a team without stepping on each other’s toes.

That’s why Git is used by developers all over the world — in open source projects, startups, and even giant companies like Google and Microsoft.

Now let’s walk through how Git actually works — using a simple step-by-step diagram.


The Git Workflow: Step by Step

How Git Works (Step-by-Step)

We’ll start on the left, with your working directory. This is where your project lives — it’s just a normal folder on your computer.

When you create or edit a file, it starts off as untracked. That means Git knows the file exists, but it’s not keeping tabs on it yet.

To tell Git, “Hey, I want to track this,” you use the command: git add This moves the file from the working directory to the staging area.

The staging area is like a prep zone — it holds all the changes you want to save in your next snapshot.

Once your changes are ready, you commit them. To do this, you type: git commit -m "your message" This saves the changes to the committed files area — also called your local repository. Think of this as your personal history of changes.

So far, everything is still on your computer.


Sharing and Syncing with Remote

Now, let’s say you want to share your changes with your team — or back them up online.

You use the command: git push This takes your committed changes and sends them to the remote repository — which is usually hosted on GitHub, GitLab, or something similar.

The remote repo is the shared version of your project. Everyone on your team can pull from it and push to it.

To bring down changes made by others, you can use: git fetch, which downloads changes but doesn’t apply them yet. Or, you can use git pull, which fetches and then automatically updates your local files.

That’s how you keep your project in sync with the rest of your team.


Switching and Combining Work

Sometimes, you want to go back to a previous version of your code or switch to a different branch.

To do that, you use the command: git checkout This lets you move between different versions of your project.

If you’ve been working in a feature branch and want to bring those changes into your main project, you can use: git merge This combines the changes from one branch into another — and Git takes care of the rest.

If the same file was changed in both places, Git will ask you to resolve any conflicts before finishing the merge.

These tools — checkout and merge — are what make Git so powerful for managing multiple versions and working with teams.


Wrap-Up

Let’s do a quick recap.

Your journey starts in the working directory, where you make changes.

Then you stage them with git add, and save them permanently with git commit

To share your work, you use git push to send it to a remote repo, and git pull or git fetch to stay updated with your team. 

You can switch versions using git checkout, and combine work with git merge.

That’s the core Git workflow — simple, powerful, and incredibly useful.

In future lessons, we’ll go deeper into branches, resolving conflicts, and using GitHub.

Thanks for reading, and I’ll see you in the next one!

Comments

Spring Boot 3 Paid Course Published for Free
on my Java Guides YouTube Channel

Subscribe to my YouTube Channel (165K+ subscribers):
Java Guides Channel

Top 10 My Udemy Courses with Huge Discount:
Udemy Courses - Ramesh Fadatare