Fundamentals 7 min read

Why Every Developer Must Master Git: From Basics to Practice (Part 1)

This article introduces Git by explaining its evolution, core advantages, key concepts such as the three work areas, file states and object types, and provides practical command examples, commit conventions, .gitignore setup, common pitfalls, and a preview of the next part on branching strategies.

Coder Trainee
Coder Trainee
Coder Trainee
Why Every Developer Must Master Git: From Basics to Practice (Part 1)

Git basics and practical pitfalls

Git commands look simple, but in production a merge conflict, an accidental rebase, or other mistakes can cause serious problems.

1. What is Git and why use it?

1.1 Evolution of version‑control systems

┌───────────────────────────────────────────────────────┐
│               Version‑control evolution               │
├───────────────────────────────────────────────────────┤
│   Local VCS   │   Centralized VCS   │   Distributed VCS │
│   RCS         │   CVS / SVN         │   Git / Mercurial │
│   Only local │   Single server     │   Every clone is a full repo │
│   No collaboration │   Single point of failure │   No single point of failure │
│   No network needed │   Network required │   Works offline │
└───────────────────────────────────────────────────────┘

1.2 Core advantages of Git

Distributed : each developer has a complete repository history locally.

Snapshot storage : Git stores full file‑state snapshots, not line‑by‑line diffs.

Data integrity : all objects are addressed by SHA‑1 hashes, making the data tamper‑proof.

Lightweight branch model : creating and switching branches has near‑zero cost.

Local operations : most actions run locally, providing fast feedback.

2. Core concepts

2.1 Three work areas

┌─────────────────────────────────────────────────────┐
│               Git work areas diagram               │
│   Working Directory ──git add──► Staging Area      │
│   (files on disk)          (index)                │
│          │                 │                     │
│          ▼                 ▼                     │
│   git commit ──► Local Repository ──git push──► Remote Repository │
└─────────────────────────────────────────────────────┘

2.2 File states

Untracked : new file not yet managed by Git.

Modified : file changed but not staged.

Staged : file added to the index, ready to commit.

Committed : file safely stored in the local repository.

2.3 Git object types

Blob : snapshot of file content, addressed by its content hash.

Tree : directory structure that records file names and references to blobs.

Commit : a commit object linking a tree, parent commits, author information, and a commit message.

3. Basic commands in practice

3.1 Initialize and clone

# Initialize a new repository
git init

# Clone a remote repository
git clone https://github.com/user/repo.git

# Clone into a specific directory
git clone https://github.com/user/repo.git my-folder

3.2 Daily development workflow

# 1. Check repository status
git status

# 2. View differences
#   working tree vs. staging area
git diff
#   staging area vs. HEAD (last commit)
git diff --staged

# 3. Stage changes
git add file.txt          # stage a single file
git add .                 # stage all changes in the current directory (use with care)
git add -p                # interactively select hunks

# 4. Commit staged changes
git commit -m "feat: add user login feature"

# 5. Inspect commit history
git log               # full history
git log --oneline     # concise one‑line per commit
git log --graph       # graphical representation
git log -p            # show diff for each commit

3.3 Conventional commit messages

# Example Conventional Commits
git commit -m "feat: add user login feature"
git commit -m "fix: correct order amount calculation"
git commit -m "docs: update README"
git commit -m "refactor: restructure order service"

# Type meanings
# feat     – new feature
# fix      – bug fix
# docs     – documentation update
# style    – code style changes (no functional impact)
# refactor – code refactor (no functional change)
# test     – test related changes
# chore    – build or tooling changes

4. .gitignore configuration example

# Build artifacts
target/
*.class
*.jar

# IDE configuration
.idea/
*.iml
.vscode/
.settings/

# Log files
*.log
logs/

# Environment files
.env
application-local.yml
application-dev.yml

# System files
.DS_Store
Thumbs.db

5. Common misconceptions

5.1 Difference between git add . and git add -A

git add .   # adds all changes in the current directory and its sub‑directories (new, modified, but not deletions)
git add -A  # adds all changes, including deletions and renames
git add -u  # adds changes to already tracked files only (no new files)

5.2 Commit message quality

# ❌ Poor examples
git commit -m "fix"
git commit -m "修改"
git commit -m "update"

# ✅ Good examples following Conventional Commits
git commit -m "fix: resolve concurrency issue in order status update"
git commit -m "feat: add user points feature"
git commit -m "refactor: extract common utils to common module"
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

GitVersion ControlDistributed VCSGit CommandsGitignoreCommit Conventions
Coder Trainee
Written by

Coder Trainee

Experienced in Java and Python, we share and learn together. For submissions or collaborations, DM us.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.