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:

  • Understand the Git workflow.
  • Create and modify files.
  • Check the status of your repository.
  • Stage changes.
  • Commit changes.
  • View commit history.
  • Understand the Git lifecycle.

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:

  • Creating a new file
  • Modifying an existing file
  • Deleting a file

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:

  • Visual Studio Code
  • File Explorer
  • Command Prompt

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:

  • Be short and descriptive.
  • Explain what changed.
  • Use the imperative mood (e.g., “Add”, “Update”, “Fix”).

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:

  • Understand the Git workflow.
  • Create and modify files.
  • Identify untracked and modified files.
  • Stage changes using git add.
  • Commit changes with git commit.
  • Review commit history using git log.
  • Interpret the output of git status.

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


Next Tutorial

The next chapter will cover:

  • Pushing commits to your self-hosted GitLab server using git push
  • Pulling the latest changes using git pull
  • Synchronizing your local and remote repositories
  • Handling push conflicts
  • Understanding when to use git fetch versus git pull

Click Here to view the Next tutorial.


Tutorial Index:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.