LATEST 🚀 Welcome to Upgradix by Shrash Studio – Your destination for free technology learning and career growth.
🕘 Updated:
Git & GitHub

Git Fundamentals – Understanding the Git Workflow

Git is a version control system that tracks changes in your project files. It helps developers work safely, review changes and return to earlier versions. Teams use this workflow every day while building applications.

Git Fundamentals – Understanding the Git Workflow

Understand how Git tracks changes, manages versions, and helps developers work together on software projects.

Git & GitHub Beginner Level Practical Tutorial 2026 Learning Series
TL;DR – What You Will Learn

Git is a distributed version control system that records changes in your source code. Its workflow revolves around three important areas: the working directory, staging area, and repository. You will learn how to track files, stage changes, commit them, inspect history, and understand how Git maintains different versions of your project.

1. The Problem: Why Do Developers Need Version Control?

Imagine you are developing an employee management application. You create a feature, fix a few bugs, and then modify the same files to introduce another feature.

After several changes, the application stops working. You now need to identify what changed, when it changed, and how to return to the earlier working version.

Without version control, developers often create multiple copies of project folders:

A common manual backup approach
EmployeeManagement/
EmployeeManagement_Final/
EmployeeManagement_Final_New/
EmployeeManagement_Final_Updated/
EmployeeManagement_Final_Updated_2/

This approach quickly becomes difficult to maintain. It is also hard to identify which files changed and which version is correct.

Version control solves this problem by maintaining a history of changes in a structured way.

2. What Is Git?

Git is a free, open-source, distributed version control system. It helps developers track changes to files, maintain project history, compare versions, and collaborate with other developers.

Git was originally created by Linus Torvalds in 2005 to support the development of the Linux kernel.

Important characteristics of Git

  • Distributed: Each developer can maintain a complete local repository with project history.
  • Version tracking: Git records committed changes over time.
  • Branching: Developers can work on separate features without directly changing the main development line.
  • Collaboration: Changes can be shared between repositories.
  • Performance: Most everyday operations are performed locally.
  • Integrity: Git uses cryptographic hashes to identify and protect the integrity of repository objects.
Git vs GitHub

Git is the version control tool installed on your computer. GitHub is a cloud-based platform that hosts Git repositories and provides collaboration features such as pull requests, issues, code reviews, and project management.

3. Understanding the Three Main Areas of Git

Before learning Git commands, it is important to understand how Git manages changes. The basic Git workflow involves three main areas.

3.1 Working Directory

The working directory is the folder where you create, edit, delete, and manage your project files.

For example, when you modify EmployeeService.cs, the changes initially exist in your working directory.

3.2 Staging Area

The staging area is where you prepare changes that you want to include in your next commit.

You can stage selected files instead of committing every modification in your working directory.

3.3 Local Repository

The local repository stores committed snapshots and the history of your project. When you create a commit, Git records the staged changes as a new version in the repository.

The Git workflow diagram

Working Directory Edit and create files Unstaged changes Staging Area Prepare selected changes Ready to commit Local Repository Save project snapshot Committed history git add git commit Further edits begin the next development cycle

The fundamental Git workflow: edit files, stage selected changes, and commit them.

4. Understanding the Git Workflow Step by Step

Let's understand the complete workflow using a practical Employee Management application.

Step 1 – Create or open your project

Start with your project folder. If Git is not initialized, create a repository using git init.

Terminal – Initialize a repository
mkdir EmployeeManagement
cd EmployeeManagement

git init
Step 2 – Create a project file

Create a file named README.md to describe your project.

README.md
# Employee Management

A sample application to manage employee information.

## Features
- Add employees
- Update employee details
- View employee records
Step 3 – Check the current status

Use git status to understand which files are untracked, modified, or staged.

Terminal
git status
On branch main No commits yet Untracked files: README.md nothing added to commit but untracked files present

Git identifies the README file as untracked because it has not yet been added to the repository's staging area.

Step 4 – Stage the file

Use git add to prepare the file for the next commit.

Terminal
git add README.md

The file is now staged. Git is ready to include this version of the file in a commit.

Step 5 – Create a commit

A commit records the staged changes as a new project snapshot.

Terminal
git commit -m "Add project README"
[main (root-commit) a1b2c3d] Add project README 1 file changed, 8 insertions(+) create mode 100644 README.md

Your first commit has been created. Git now has a recorded version of your project.

Step 6 – Modify an existing file

Add another line to README.md or create a new file. Then run git status again to inspect the changes.

Terminal
git status
On branch main Changes not staged for commit: modified: README.md no changes added to commit

The file is modified, but these new changes have not yet been staged.

Step 7 – Stage and commit the new changes

Stage the modified file and create another commit.

Terminal
git add README.md
git commit -m "Update project documentation"

You now have two commits in your repository. Each commit represents a recorded state of your project.

5. Understanding the Most Important Git Commands

These are the essential commands you will use frequently while working with Git.

Command Purpose
git init Initialize a new local Git repository.
git status Show the current state of files.
git add Stage changes for the next commit.
git commit Record staged changes in the repository.
git log Display commit history.
git diff Show differences between file versions or Git states.
git restore Restore working-tree files or unstage changes with the appropriate option.
git rm Remove files from the working tree and stage the removal.
git branch List, create, or manage branches.
git switch Switch between branches.

6. Understanding Git Commit History

One of Git's most useful features is its ability to maintain project history. Every commit has a unique identifier and records information about the changes.

Terminal – View commit history
git log
commit a1b2c3d... Author: Developer Date: Sat Nov 14 10:30:00 2026 Add project README commit e4f5g6h... Author: Developer Date: Sat Nov 14 10:15:00 2026 Initial project setup

To view a compact history, use:

Terminal
git log --oneline
a1b2c3d Update project documentation e4f5g6h Add project README

This makes it easier to understand how your project has evolved over time.

7. Understanding Git Diff

The git diff command helps you inspect changes before committing them.

For example, if you modify README.md, run:

Terminal
git diff
diff --git a/README.md b/README.md index 1234567..abcdef0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # Employee Management A sample application to manage employee information. + +## Technologies +.NET and SQL Server

Lines beginning with + represent additions, while lines beginning with - represent removals.

To inspect changes already staged for commit, use:

Terminal
git diff --staged
Important distinction

git diff normally compares working-tree changes against the index. git diff --staged compares staged changes against the latest commit.

8. What Happens When You Commit?

A commit is not simply a copy of your entire project folder. Git stores objects representing file content and repository history, and each commit points to a snapshot of the project.

A commit contains information such as:

  • A unique commit identifier (hash).
  • The author and committer information.
  • A timestamp.
  • A commit message.
  • A reference to the project's snapshot tree.
  • Parent commit reference or references, depending on the commit type.

This structure allows Git to reconstruct project history and identify how the project changed between commits.

9. Local Repository vs Remote Repository

Git is distributed, which means developers can work with local repositories independently. A remote repository provides a shared location where developers can exchange their changes.

Developer A Local Repository Own commits and history Remote Repository Shared project history Hosted on GitHub Developer B Local Repository Own commits and history Push Pull Pull Push Developers exchange commits through a shared remote repository

A distributed Git workflow: developers work locally and synchronize through a remote repository.

Some commonly used remote commands are:

Terminal – Remote operations
# Connect a remote repository
git remote add origin https://github.com/username/EmployeeManagement.git

# Upload local commits
git push -u origin main

# Download and integrate remote changes
git pull

# Download remote references and objects without integrating
git fetch

We will explore remote operations and GitHub collaboration in detail in the upcoming articles.

10. Common Git Mistakes Beginners Should Avoid

  • Committing everything blindly: Always inspect the staged changes before committing.
  • Using unclear commit messages: Write messages that explain the purpose of the change.
  • Ignoring Git status: Check your working-tree state before and after important operations.
  • Committing sensitive information: Never commit passwords, API keys, private certificates, or credentials.
  • Mixing unrelated changes: Keep commits focused on a logical unit of work.
  • Confusing Git with GitHub: Remember that Git works locally; GitHub hosts repositories and collaboration features.

11. Best Practices for a Clean Git Workflow

1. Check your status regularly

Use git status to understand the current state of your project.

2. Review changes before staging

Use git diff to inspect modifications before preparing them for a commit.

3. Create meaningful commits

Use short, descriptive messages that explain what the commit accomplishes.

4. Commit small, logical changes

Prefer focused commits that are easier to review, test, and understand.

5. Use branches for independent work

Keep feature development separate from the main development line. Learn branching and merging in the upcoming lessons.

12. Interview Questions and Answers

Q1. What is Git?

Git is a distributed version control system used to track changes in source code, maintain project history, and support collaboration between developers.

Q2. What is the difference between Git and GitHub?

Git is a version control tool used to manage source code changes. GitHub is a platform that hosts Git repositories and provides collaboration capabilities such as pull requests, issues, and code reviews.

Q3. What are the three main areas in the Git workflow?

The three main areas are the working directory, staging area, and local repository.

Q4. What is the purpose of git add?

The git add command stages selected changes so that they can be included in the next commit.

Q5. What is a Git commit?

A commit is a recorded snapshot of the staged project changes. It includes metadata and a reference to the committed project state.

Q6. Can we commit without using git add?

A normal commit records staged changes. However, commands such as git commit -a can automatically stage modifications and deletions of already tracked files before committing. It does not automatically include new untracked files.

Q7. What is the difference between git fetch and git pull?

git fetch downloads remote changes and updates remote-tracking references without integrating them into the current branch. git pull fetches and then integrates changes into the current branch, typically through merge or rebase depending on configuration and options.

Q8. Is Git a centralized or distributed version control system?

Git is a distributed version control system. Each clone normally contains the repository history needed for local operations.

13. Hands-on Practice

Let's apply what you have learned. Create a simple Git repository and complete the following tasks.

Practice Task – Employee Management Repository
  1. Create a folder named EmployeeManagement.
  2. Initialize Git using git init.
  3. Create a README.md file.
  4. Check the repository status.
  5. Stage the README file.
  6. Create your first commit.
  7. Modify the README file.
  8. Inspect the changes using git diff.
  9. Stage and commit the updated file.
  10. Review your commit history using git log --oneline.

Expected final workflow

Terminal – Complete command sequence
mkdir EmployeeManagement
cd EmployeeManagement

git init

echo "# Employee Management" > README.md

git status

git add README.md

git commit -m "Add project README"

echo "A sample employee management application" >> README.md

git diff

git add README.md

git commit -m "Update project description"

git log --oneline
Practice tip

Do not just copy and execute the commands. After each command, run git status and observe how the file moves between untracked, staged, modified, and committed states.

14. Key Takeaways

  • Git is a distributed version control system.
  • The working directory is where you make changes.
  • The staging area prepares selected changes for a commit.
  • The local repository stores commits and project history.
  • git add stages changes.
  • git commit records staged changes.
  • git status, git diff, and git log help you inspect your project.
  • Remote repositories allow developers to exchange commits and collaborate.

15. Official Learning Resources

What's Next?

You now understand the fundamental Git workflow: working directory, staging area, and commits. In the next article, we will explore commonly used Git commands in detail, with practical examples and real-world development scenarios.

Next Article: Git Commands – Essential Commands Every Developer Should Know

Upgradix by Shrash Studio

Learn Technology. Build Your Future.

Comments & Ratings (0)

Log in or create a student account to comment and rate this article.

Be the first to comment on this article.