Kritim Yantra
Apr 26, 2025
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! π
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.
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.
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.
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
!
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
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!
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!
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.
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 |
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! π
No comments yet. Be the first to comment!
Please log in to post a comment:
Sign in with Google