Advanced Git Topics Explained Simply (With Examples)

Author

Kritim Yantra

Apr 26, 2025

Advanced Git Topics Explained Simply (With Examples)

If you already know the basics of Git β€” like clone, commit, push, and pull β€” that’s amazing! πŸŽ‰

Now, it’s time to go a little deeper and learn some advanced Git concepts that real developers use daily.

Don’t worry β€” I’ll explain everything in simple language with practical examples.
Let’s dive in! πŸš€


🌟 1. Git Stash β€” Save Your Work Temporarily

Problem:
You're halfway through coding something, but suddenly your boss says,
"Quick! Fix a bug in another file!"

You don’t want to commit half-finished work, right?
Here’s where git stash helps!

Command:

git stash

This hides your uncommitted changes safely.

Now, fix the urgent bug!

Later, bring your old work back with:

git stash pop

Example:

# Working on feature A
git stash   # Saves your messy work

# Fix urgent bug
# Commit bugfix

git stash pop  # Get your messy work back

πŸ‘‰ Tip:
Use git stash list to see multiple saved works.


🌟 2. Git Revert β€” Undo a Commit (Safely)

Problem:
You pushed a wrong commit to GitHub. Now what?
Deleting history can be dangerous in a team.

Instead, safely create a new commit that undoes the wrong one using git revert.

Command:

git revert <commit-id>

Git will create a new "undo" commit.

Example:

git log   # Copy the wrong commit ID
git revert a1b2c3d

βœ… Now the project is safe again, and your history is clean.


🌟 3. Git Rebase β€” Cleaner History

Normally, you merge branches into main, but it creates many extra merge commits.

If you want a clean, straight-line history, you can rebase instead of merge.

Command:

git checkout your-feature-branch
git rebase main

This moves your commits on top of the latest main branch.

Example:

git pull origin main
git checkout feature-login
git rebase main

πŸ‘‰ Important:
If you already pushed your branch to GitHub, rebasing can cause problems.
Only rebase local branches you haven't shared yet.


🌟 4. Git Cherry-Pick β€” Pick Only One Commit

Problem:
You made a great bug fix on one branch and want that fix in another branch without copying the whole branch.

Use cherry-pick to copy one single commit to another branch!

Command:

git cherry-pick <commit-id>

Example:

git checkout main
git cherry-pick a1b2c3d

βœ… Now only that specific bug fix is added to main!


🌟 5. Git Tag β€” Mark Special Points (like Releases)

When you release a project version, like v1.0, it’s smart to create a tag.

Command:

git tag v1.0
git push origin v1.0

Now, you can always go back to this stable version if needed.

Example:

git tag -a v1.0 -m "First official release"
git push origin v1.0

πŸ‘‰ Bonus Tip:
See all tags with:

git tag

🌟 6. Git Clean β€” Remove Untracked Files

Sometimes, your project folder gets messy with random temp files.

If you want to delete all untracked files safely:

Command:

git clean -f

To do a dry run (preview without deleting):

git clean -n

βœ… Helps keep your folder neat and clean!


🌟 7. Git Log with Pretty Graphs

Want to see a cool graph of all commits and branches?

Use:

git log --oneline --graph --all

Example output:

* 1f2d3a4 (HEAD -> main) Add new feature
* 5e6d7f8 Fix bug in login
* 7a8b9c0 Initial commit

πŸ‘‰ It makes history easy to understand, especially when working in teams!


🌟 8. Git Amend β€” Edit Your Last Commit

Forgot to add a file?
Made a typo in your commit message?

Instead of making a new commit, you can fix the last one:

Command:

git commit --amend

Example:

# Oops forgot to add one file
git add missedfile.txt
git commit --amend

Now your last commit includes the missed file, and you can even edit the commit message.


🎯 Summary

Feature Purpose
stash Save messy work temporarily
revert Undo a bad commit safely
rebase Create cleaner project history
cherry-pick Copy a specific commit
tag Mark important points (releases)
clean Remove untracked files
log --graph See beautiful project history
amend Fix your last commit

πŸ”₯ Final Thoughts

These advanced Git tools can save hours of your time, keep your project clean, and make you look professional.

You don't need to memorize everything right now.
Just practice one feature at a time when the situation comes.

Pro Tip: Bookmark this blog and come back whenever you get stuck! πŸ“‘

Tags

Git

Comments

No comments yet. Be the first to comment!

Please log in to post a comment:

Sign in with Google

Related Posts