๐Ÿ“ Git & GitHub

What Is a Git Commit and Why Do You Need It? ๐Ÿ“ธ

0
Author
04e5cc8b-58ac-4bdc-bdee-661bbb
๐Ÿ“…
Published
06.05.2026
โฑ๏ธ
Reading time
4 min
๐Ÿ‘๏ธ
Views
55
๐ŸŒฑ
Level
Beginner

A commit is a saved snapshot of your project at a specific point in time โ€” like a save point in a video game!

What Is a Commit

In Simple Terms

Imagine you’re writing a book:

  • Without Git: You write all day, your computer crashes, and all the text is lost ๐Ÿ˜ฑ
  • With Git commits: Every 30 minutes you make a “save” โ†’ you can roll back to any point โœ…

Commit = checkpoint in your code!

What’s Stored in a Commit?

Every commit contains:

  1. Snapshot of files โ€” a full snapshot of the project
  2. Author โ€” who made the changes
  3. Date and time โ€” when it was done
  4. Message โ€” what changed (commit message)
  5. Unique ID โ€” hash (e.g.: a1b2c3d...)
  6. Reference to parent โ€” the previous commit

It’s like a photograph:
- A snapshot of the moment โœ…
- With date and signature โœ…
- Can be viewed later โœ…

Why Do You Need Commits?

1. Change History ๐Ÿ“œ

# You can see EVERYTHING that happened:
commit a1b2c3d
Author: Ivan
Date: April 10, 4:30 PM
fix: fix auth bug

commit x7y8z9w
Author: Maria
Date: April 10, 2:15 PM
feat: add registration form

You can answer questions like:
- Who wrote this code?
- When was this feature added?
- Why was this file changed?

2. Reverting Changes โฎ๏ธ

Imagine:
- Added a new feature โ†’ everything broke
- With commits: roll back 1 hour โ†’ everything works!

# One command โ€” and you're back in time
git checkout previous-commit

Without commits: Ctrl+Z won’t help once you’ve closed the editor!

3. Team Collaboration ๐Ÿ‘ฅ

The problem:
- You’re working on app.py
- A colleague is also changing app.py
- How do you combine?

The solution โ€” commits!
- Each person makes their own commits
- Git knows how to merge
- Conflicts are resolved transparently

4. Code Backup ๐Ÿ’พ

Commits on GitHub = cloud backup:
- Your computer burns down โ€” code is safe โœ…
- Accidentally deleted a file โ€” restored โœ…
- Virus encrypted the drive โ€” clone from GitHub โœ…

Commit in Detail

Commit vs Saving a File

Action Save File (Ctrl+S) Git Commit
What Writes file to disk Saves a project snapshot
History No history Full history
Rollback Can’t go back Can roll back to any point
Team Who, what, when โ€” unknown Author, date, message visible
Backup Only on your PC Syncs with GitHub

Takeaway: Ctrl+S saves the file, Git commit saves a MOMENT in the project’s history!

Example Commit

# 1. Changed the file
echo "print('Hello')" > app.py

# 2. Added to staging
git add app.py

# 3. Made a commit
git commit -m "feat: add greeting function"

# Result:
[main a1b2c3d] feat: add greeting function
1 file changed, 1 insertion(+)

What happened:
1. Git took a snapshot of the current state
2. Recorded it in history with your message
3. Assigned unique ID a1b2c3d

Anatomy of a Commit

git log

Shows:

commit a1b2c3d4e5f6g7h8i9j0  โ† Unique hash
Author: Ivan Ivanov <ivan@example.com>  โ† Who
Date:   Thu Apr 10 16:30:00 2026 +0300  โ† When

    feat: add registration form  โ† What (commit message)

    - Created /register page
    - Email and password validation
    - Database integration

How to Commit Correctly

How Often to Commit?

โœ… Good practice:

1 commit = 1 logical change

Examples:
- Fixed a bug โ†’ commit
- Added a feature โ†’ commit
- Updated README โ†’ commit
- Refactored a function โ†’ commit

Rule of thumb: every 30-60 minutes of work or after completing a task

โŒ Bad practice:

Too rarely:

# Worked for a week โ†’ 1 giant commit
git commit -m "done"  # 150 files changed!

Problems:
- Impossible to understand what changed
- Can’t partially revert
- Code review is a nightmare

Too often:

git commit -m "added 1 line"  # ร— 50 times per hour

Problems:
- History is polluted
- Hard to find the change you need

The sweet spot:

# Monday
git commit -m "feat: add user model"
git commit -m "feat: create login form"
git commit -m "fix: fix email validation"

# = 3 clear commits for the day

What NOT to Commit?

โŒ Never:
- Passwords, API keys, tokens
- .env file with secrets
- node_modules/, __pycache__/
- Large binary files (videos, archives)
- Temp files, logs

Use .gitignore!

Commits and GitHub

Local commits:
- Made on your computer
- Nobody sees them yet
- Can be changed/deleted

After push:
- Commits are on GitHub
- Visible to the entire team
- Harder to change (requires force push)

Visualization and Tools

Visual Representation

Time โ†’

[Commit 1]     [Commit 2]     [Commit 3]     [Commit 4]
  Init           Add login      Fix bug       Add docs
    โ†“                โ†“              โ†“              โ†“
mainโ”€โ”€โ—โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ—โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ—โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ—โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ†’

Each โ— = a commit = a point in the project’s history!

You can jump to any of them:

git checkout Commit-2  # returned to the "Add login" moment

Commits in GitHub Desktop

Visual process:

  1. Changes โ€” see modified files
  2. Diff โ€” see what exactly changed (green/red)
  3. Summary โ€” write commit message
  4. Commit to main โ€” snapshot the moment!
  5. Push โ€” send to GitHub

Clear and visual! ๐ŸŽจ

Best Practices and Career

Best Practices

โœ… DO:
- Commit frequently (every 30-60 minutes)
- Write clear messages
- One commit = one task
- Review diff before committing
- Commit working code

โŒ DON’T:
- Giant commits (100+ files)
- Commit broken code
- Meaningless messages (“update”, “fix”)
- Commit secrets and passwords
- Commit temp files

Why This Matters for Your Career

Employers look at:

  1. GitHub profile โ€” how many commits, how often
  2. Commit quality โ€” clear messages
  3. Project history โ€” code evolution
  4. Contributions โ€” contributions to open source

Good commits = a mark of a professional! ๐Ÿ’ผ

Conclusion

Commit = save point in a game:
- Checkpoint in code โœ…
- Can roll back โœ…
- Full history of all changes โœ…
- Backup on the server (GitHub) โœ…

Start small:
1. Worked 30-60 minutes โ†’ commit
2. Fixed a bug โ†’ commit
3. Added a feature โ†’ commit
4. Updated documentation โ†’ commit

Remember: Git commits are a time machine for your code! โฐ

Next step: learn how to write proper commit messages! โœ๏ธ

Your reaction to the article

๐Ÿ’ฌ Comments (0)

๐Ÿ” Sign in to leave a comment
๐Ÿšช Login
๐Ÿ’ญ

No comments yet

Be the first to share your opinion about this article!

๐Ÿ”— Similar

Similar articles

Continue learning with these materials

๐Ÿ“

Git Hosting Platforms: Full Comparison ๐Ÿ†

GitHub, GitLab, Bitbucket โ€” which one to choose? A complete comparison with up-to-date data.

๐Ÿ“… 06.05.2026 ๐Ÿ‘๏ธ 51
๐Ÿ“

Why Git won over every other version control systโ€ฆ

Today Git is the de facto standard for version control in software development. But it...

๐Ÿ“… 06.05.2026 ๐Ÿ‘๏ธ 50
๐Ÿ“

Pull Requests: the complete guide ๐Ÿ”€

A Pull Request (PR) is a formal proposal to merge changes from one branch into...

๐Ÿ“… 06.05.2026 ๐Ÿ‘๏ธ 55

Did you like the article?

Subscribe to our updates and receive new articles first. Grow with PyLand!