DEV Community

Cover image for Git Full Speed Ahead Part 2: Organize Your Git Projects: Local Workflow Made Simple
Pawinphat Charoenrat
Pawinphat Charoenrat

Posted on • Edited on

Git Full Speed Ahead Part 2: Organize Your Git Projects: Local Workflow Made Simple

Overview

In this section, we’ll explore the typical local Git workflow — a series of commands and steps developers follow to manage code efficiently. Understanding the workflow helps you keep your project organized, track changes systematically, and collaborate smoothly with others (even when working solo!).

Whether you're just getting started or brushing up on Git fundamentals, a solid grasp of this flow will lay the groundwork for everything to come.

Table of content


GIT WORKFLOW

Git workflow


What Happens When You Run a Git Command

When You Run a Git Command


Git Workflow Overview
Here’s a quick summary of the basic Git workflow:

1. Working Directory
Start with a regular folder. Run git init to begin tracking the project with Git.

2. Untracked Files
Git sees your files but doesn't track them yet. You need to run git add to include them in version control.

3. Staging (Tracked Files)
Files you add are moved to the staging area, where Git prepares them for a commit.

4. Commit
git commit saves a snapshot of staged changes to your local repository.

5.Push to Remote
git push uploads your commits to a remote server — useful for backup or collaboration.


🧪💻 I ran the test using Git Bash, and I'm working on Windows.


🔥 GIT INIT

When starting with Git for the first time in a project, this is the command you'll need:

git init
Enter fullscreen mode Exit fullscreen mode

This initializes a new Git repository in your current directory. It sets up the .git folder, allowing Git to begin tracking changes in your project.

git init

🔥 GIT STATUS

One of the most essential Git commands — git status helps you quickly and clearly see what’s going on in your project.

📌 What does git status do?
The git status command displays the current state of your Git repository. It shows you:

  • Files that have been modified
  • Changes that are not yet staged
  • Files that are in the staging area (ready to commit)
  • Untracked files — files that Git sees but isn't tracking yet
  • The current branch name, and how it's related to the remote (e.g., ahead/behind)

It’s the first command you’ll often run before committing — like checking your dashboard before moving forward.

git status
Enter fullscreen mode Exit fullscreen mode

Example of git status command output

git status command output

🔍 Breaking Down the git status Output

1. On branch main
This tells you exactly which branch you’re currently working on — in this case, main. Knowing your branch keeps your workflow on track.

2. Untracked files:
These are brand-new files Git has spotted but isn’t tracking yet. They’re not staged, so Git’s basically saying, “Hey, did you want me to watch these?”

3. File names below this section
These are the actual files waiting in the wings — ready to be added to the staging area when you run git add.

📂 File Statuses in Git (via git status)

File Status Description How to Handle
Untracked New files not being tracked by Git git add <file> to start tracking them
Tracked - Unmodified File is being tracked and hasn't changed since last commit ✅ No action needed
Modified File has been changed but not yet staged git add <file> to stage, or git restore <file> to discard
Staged (Index) Changes have been staged and are ready to be committed git commit to save the changes
Deleted (staged) A file has been deleted and the deletion has been staged git commit to record the deletion
Deleted (unstaged) A file has been deleted but the deletion is not staged git add <file> to stage deletion or restore it
Renamed Git detects a file has been renamed (after staging) git commit to save the rename
Conflicted Merge conflict: Git can't automatically merge changes Manually resolve, then git add <file>
Ignored Files intentionally excluded via .gitignore ✅ No action needed (unless misconfigured)

💡Summary
The git status command is your go-to tool for checking what’s going on in your working directory. It shows which files have been modified, newly added, or are ready to commit. It’s an essential habit to run git status before every commit or push --helping you stay in control and avoid mistakes.

🔥 GIT ADD

📌 What is git add?

git add is the command used to move changes into the staging area, which is the step right before committing those changes into your Git repository.

✨The staging area is a temporary space where you collect the changes you intend to include in your next commit.

✅ Using git add

To stage a specific file, use:

git add <filename>
Enter fullscreen mode Exit fullscreen mode

This adds only the specified file to the staging area, preparing it to be committed.

✅ To stage all changes (including new and modified files) in the current directory and its subdirectories, use:

git add .
Enter fullscreen mode Exit fullscreen mode

Stages all changes in the current directory and its subdirectories — including new and modified files.

✅ Use this to stage only files with a specific extension (e.g., .js, .txt, etc.)

git add *.<extension>
Enter fullscreen mode Exit fullscreen mode

✅ To stage only tracked files — files that Git has seen before — use:

git add -u
Enter fullscreen mode Exit fullscreen mode

The -u flag tells Git to update the index with changes to tracked files only (modified or deleted), skipping any new untracked files.

Examples of Using git add

Examples of Using git add

🔥 GIT RM --CACHED

📌 What is git rm --cached?

The git rm --cached command is used to remove a file from the staging area (also called the index) without deleting the file from your local machine. This means the file will no longer be included in the next commit, but it still physically exists in your project folder.

✨ Use this when you want Git to stop tracking a file (untrack it), but you don’t want to actually delete the file.

🧭 Command Syntax
✅ This command removes a file from the staging area one at a time:

git rm --cached <filename>
Enter fullscreen mode Exit fullscreen mode

✅ You can use this command to remove an entire folder from the staging area:

git rm --cached -r <foldername>
Enter fullscreen mode Exit fullscreen mode

✅ Unstage All Files and Folders from the Git Index
The following command will unstage all files and folders in the current directory and all subdirectories from the Git index:

git rm --cached -r .
Enter fullscreen mode Exit fullscreen mode

In summary: This command removes all tracked files—meaning it untracks everything under your project root.

This command removes all tracked files except those explicitly excluded via your .gitignore file.

🧠 Why Use git rm --cached?

  • You accidentally added or committed files that should be ignored
  • You want Git to stop tracking files without deleting them from your local disk
  • To work with .gitignore so that files won’t be tracked in the future

⚠️ Caution
The files remain on your computer but are removed from Git tracking

If you use git rm without --cached, the files will be deleted both from the staging area and your local machine!

Command Result
git rm filename Removes the file from Git and deletes it locally
git rm --cached file Removes the file from Git but keeps it on your disk

Example of using the git rm command

git rm command

Brief Explanation of How It Works

  1. When you run git status for the first time, you will see that all files and folders have been added to the staging area.
  2. Use the command git rm --cached -r dist/ (important: don’t forget the -r !)
  3. Run git status again, and you will notice the dist folder is now marked as Untracked.

🔥 GIT COMMIT

📌 What is git commit?

The git commit command is one of the core Git commands used to save changes in your project to the repository. Git stores these changes as a "snapshot" of your files, allowing you to review or revert to them later.

✅ Using git commit

Before you can run git commit, you need to tell Git which files you want to include by using git add.

git commit -m "Add a message describing the changes here"
Enter fullscreen mode Exit fullscreen mode

Use the command git commit -m "Add a message describing the changes here" to create a commit with a message explaining your changes.

🧠 Other Related Commands
Use this to commit all changes in tracked files without needing to run git add.

git commit -a -m "message"
Enter fullscreen mode Exit fullscreen mode

Use git commit -a -m "message" to commit all changes to tracked files with a commit message, without needing to run git add first.

example of git commit

git commit

🔥 GIT LOG

📌 What is git log?

The git log command is used to show the commit history of your repository. It displays important information about each commit, such as:

  • Commit id (SHA-1 hash)
  • Author name
  • Commit date
  • Commit message

✅ Using git log

git log
Enter fullscreen mode Exit fullscreen mode

This command displays all commits, ordered from the most recent to the oldest.

git log

Example of git log

commit 69c4808ce89cd63b55e3d01c862xxxxxx (HEAD -> main)
Author: Pawinphat <xyz@e-mail.com>
Date:   Tue Jul 22 13:47:43 2025 +0700

    Head 1 : Add all files and folder
Enter fullscreen mode Exit fullscreen mode
  1. The commit ID is stored as a 40-character SHA-1 hash.
  2. The name of the person who made the commit.
  3. The date when the commit was made.
  4. The commit message.

Useful git log options

Show commits in a concise (short) format.

git log --oneline
Enter fullscreen mode Exit fullscreen mode

example git log --online

Show history for a specific file
Use this to see which commits have modified that file.

git log <filename>
Enter fullscreen mode Exit fullscreen mode

Example

git log ABC.txt
Enter fullscreen mode Exit fullscreen mode

-Show commits along with a branch structure graph

This is useful for visualizing how branches diverge and when they were merged

git log --graph --oneline --all
Enter fullscreen mode Exit fullscreen mode

Display commits with a visual branch graph
This view is useful for understanding how different branches split off from each other and when they were merged back in.

git log --graph
Enter fullscreen mode Exit fullscreen mode

Show commits of any user

git log --author="name or email"
Enter fullscreen mode Exit fullscreen mode

Use this command to show commit history filtered by author name or email.
It's useful when you want to see only the commits made by a specific person.

📌Additional Tips

  • Press q to exit the git log output screen
  • Use git log -p to view detailed code changes for each commit
  • Use git log --since="2 weeks ago" to filter commits by a specific time range

🔥 GIT RESTORE

📌 What is git restore?

git restore is a command used to safely and easily revert changes to files or restore them to a previous state.
It was introduced in Git 2.23 as a safer and clearer alternative to certain uses of git checkout.

💾 1. Discard changes to files (that haven't been added yet)
Use this when you’ve modified files but haven’t staged them, and want to undo the changes:

git restore <filename>
Enter fullscreen mode Exit fullscreen mode
  • Revert the file back to its state in the latest commit.
  • All changes in the file will be lost! (It’s not in staging and hasn’t been committed yet

Example
1.1 If you accidentally delete test.txt
1.2 Then run git status

show git status

1.3 You’ll see that Git has detected the file test.txt as deleted.
1.4 When we run the command

git restore test.txt
Enter fullscreen mode Exit fullscreen mode

1.5 We will restore the file to its state before it was deleted.

git restore

1.6 The system will restore the file to the state before it was deleted.

restore the file to the state before it was deleted

💾 2. Unstage files (that have already been added)
Use this when you’ve added files to the staging area by mistake and want to remove them from staging without losing your changes.

git restore --staged <file>
Enter fullscreen mode Exit fullscreen mode

Removes the file from the staging area (similar to git reset filename.txt)
but does not delete the actual changes made to the file.

Example:

git restore --staged main.c
Enter fullscreen mode Exit fullscreen mode

🎉 Now that you understand these basic commands—whether it's starting a project with git init, adding files to the staging area with git add, recording changes with git commit, or checking status and history with git status and git log—you've laid a solid foundation for working with Git at the local repository level.

In the next chapter (Part 3), we'll build on this by exploring collaboration with others through remote repositories using commands like git push, git pull, and git clone, so you can manage projects smoothly with your team.


Top comments (0)