Site icon Student Projects Live

Git Workflow – Creating, Staging, and Committing Changes

Understanding and Resolving Merge Conflicts in GIT

Git Tutorial – Part 3: Git Workflow – Creating, Staging, and Committing Changes

In this tutorial we will explain Git Workflow – Creating, Staging, and Committing Changes. You will learn how to:


Understanding the Git Workflow

Git tracks changes through four main stages:

Working Directory
       │
       ▼
Staging Area (Index)
       │
       ▼
Local Repository
       │
       ▼
Remote Repository (GitLab)

Working Directory

The Working Directory contains the files and folders you are currently editing.

Examples:

At this stage, Git has detected changes but has not yet prepared them for a commit.


Staging Area

The Staging Area (also called the Index) is where you select the changes you want to include in your next commit.

Only staged changes are committed.


Local Repository

The Local Repository stores the commit history on your computer.

Each commit creates a permanent snapshot of your project.


Remote Repository

The Remote Repository is your project stored on your organization’s self-hosted GitLab server.

Commits remain local until you push them to GitLab.


Step 1: Open Your Project

Open Visual Studio Code.

Open the integrated terminal.

Navigate to your repository.

Example:

cd C:\Projects\gittutorial

Step 2: Check the Repository Status

Run:

git status

Example output:

On branch main

Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

A “working tree clean” message means there are no changes to commit.


Step 3: Create a New File

Create a file named:

notes.txt

You can create it using:

Example using Command Prompt:

echo Git Tutorial > notes.txt

Step 4: Check Status Again

Run:

git status

Example:

Untracked files:

notes.txt

What is an Untracked File?

An untracked file is a file that Git has never seen before.

Git will not include it in a commit until you explicitly add it to the Staging Area.


Step 5: Stage the File

Run:

git add notes.txt

Stage all changed files instead:

git add .

Note: git add . stages all new, modified, and deleted files in the current directory and its subdirectories.


Step 6: Verify the Staging Area

Run:

git status

Example:

Changes to be committed:

new file: notes.txt

The file is now staged and ready to be committed.


Step 7: Commit the Changes

A commit saves the staged changes into your local repository.

Run:

git commit -m "Add notes.txt"

Example output:

[main abc1234] Add notes.txt

1 file changed, 1 insertion(+)
create mode 100644 notes.txt

Commit Message Best Practices

A good commit message should:

Examples:

Add login page

Fix calculation bug

Update README

Remove unused files

Step 8: Check Status After the Commit

Run:

git status

Example:

On branch main

nothing to commit, working tree clean

Your changes are safely stored in your local repository.


Step 9: View Commit History

Run:

git log

Example:

commit abc123456789...

Author: John Smith

Date: Tue Jul 14 10:20:00 2026

    Add notes.txt

To view a shorter version:

git log --oneline

Example:

abc1234 Add notes.txt

This is useful for quickly reviewing recent commits.


Step 10: Modify an Existing File

Open notes.txt and add another line:

This is my second change.

Save the file.

Run:

git status

Example:

Changes not staged for commit:

modified: notes.txt

Git has detected the modification, but it has not yet been staged.


Step 11: Stage and Commit the Modification

Stage the updated file:

git add notes.txt

Commit the change:

git commit -m "Update notes.txt"

Now your local repository contains two commits.


Git Lifecycle Summary

Create or Modify File
        │
        ▼
git status
        │
        ▼
git add
        │
        ▼
git status
        │
        ▼
git commit
        │
        ▼
git log

Common Git Commands

CommandDescription
git statusDisplays the current status of the repository.
git add <file>Stages a specific file.
git add .Stages all changes in the current directory.
git commit -m "message"Creates a new commit with a message.
git logDisplays the complete commit history.
git log --onelineDisplays a concise commit history.

Summary

In this chapter, you learned how to:

You now have the essential skills to manage changes in your local Git repository.


Next Tutorial

The next chapter will cover:

Click Here to view the Next tutorial.


Tutorial Index:

Exit mobile version