12 Advanced Git Commands Every Developer Should Know
Oct 14, 2024
|12 min read
Git is a powerful tool that goes far beyond basic commands like git add, git commit, and git push. Once you're familiar with the basics, it's time to dive into more advanced commands that can optimize your workflow. In this post, we'll explore 12 advanced Git commands every developer should know.

Show Only My Commits with a Colorized Date
Use this command to display only your commits with a nicely colorized date:
git log --all --author="Your Name or Email" --pretty=format:"%C(yellow)%h %C(cyan)%ad%C(reset) | %s" --date=shortShow a Graph of Commits with Branches and Tags
Visualizing your commit history is easy with this command:
git log --graph --oneline --decorate --allFind the Commit that Introduced a Bug with git bisect
This command helps you find the specific commit that introduced a bug:
git bisect start
git bisect bad # Mark the current commit as bad
git bisect good <commit_hash> # Mark an earlier commit as goodThis command runs through a series of tests to identify the problematic commit, which is highly useful in large projects.
Interactive Rebase to Rewrite Commit History
Need to clean up your commit history? Try an interactive rebase:
git rebase -i HEAD~nStash Uncommitted Changes with a Message
When you need to switch branches but don't want to lose your work, stash it:
git stash push -m "Your stash message"To retrieve it later, use:
git stash applyCherry-pick a Specific Commit from Another Branch
Pull a specific commit from a different branch with:
git cherry-pick <commit_hash>Undo the Last Commit but Keep Changes
Undo your last commit without losing your changes using:
git reset --soft HEAD~1--soft resets the commit but leaves your changes staged, ready for you to
amend or recommit.
Show What Files Have Changed Between Two Branches
Easily compare the changes between branches:
git diff branch1..branch2 --name-onlyList All the Files That Changed in a Commit
View the files modified in a specific commit:
git diff-tree --no-commit-id --name-only -r <commit_hash>Squash Multiple Commits into One
Simplify your commit history by squashing several commits into one:
git rebase -i HEAD~nIn the interactive editor, replace pick with squash for the commits you want to combine.
List Untracked Files Only
If you want to see only the files not tracked by Git:
git ls-files --others --exclude-standard.gitignore.Clean Up Local Branches That Have Been Merged
Get rid of merged branches in your local repo with this command:
git branch --merged | grep -v "\*" | xargs -n 1 git branch -dThis command deletes all local branches that have already been merged into the current branch. It keeps your repository clean and organized.
Conclusion
These 12 advanced Git commands will enhance your Git workflow, helping you manage your projects more efficiently. From cleaning up branches to visualizing commit history, mastering these commands can save you significant time and effort.
Start integrating these commands into your daily workflow for better project management and version control.
Learn about Git workflows like GitFlow or Forking Workflow to further streamline your development process.
By mastering advanced Git techniques, you'll improve your productivity and gain a deeper understanding of how to manage your codebase effectively.
TABLE OF CONTENTS