DEV Community

Cover image for 10 Git Commands You’ll Wish You Knew Earlier

10 Git Commands You’ll Wish You Knew Earlier

Balraj Singh on February 17, 2025

Git can be intimidating when you’re just starting out. Most developers stick to git add, git commit, and git push, and for the most part, that’s en...
Collapse
 
justvicktor profile image
Vicktor

In number 4, git stash is the one that stashes your changes so you can safely switch branches e.g. feature-branch -> main branch.

git stash pop "pops" your most recent changes when you come back to the feature-branch so you can pick up where you left off.

Collapse
 
diyadude profile image
Diyar Qobadi

the first two commands were new to me
huge thanks )

Collapse
 
faraz_sabir_39348c9bb26be profile image
Faraz Sabir

Thanks 👍

Collapse
 
balrajola profile image
Balraj Singh

Happy to help!

Collapse
 
oculus42 profile image
Samuel Rouse

This a great list!

I usually go with git commit --amend when I need to fix or update a commit rather than git resetgit reset --soft HEAD~1, though if you've accidentally added a file to the reporeset` is a much easier fix.

There are also great tools for viewing git blame off the command line, like the built-in tools of WebStorm or GitLens for VS Code.

Thanks for putting this list together!

Collapse
 
ramkumar-m-n profile image
Ramkumar M N

Hi Balraj Singh,
Good article, you explain it well.

Checkout the following post to know few more git commands which we shall consider.

dev.to/ramkumar-m-n/19-mind-blowin...

Regards,
Ram

Collapse
 
victoriuswealth profile image
Nick Efe Oni

Great list! Another command that has saved me countless times is git worktree. It allows you to check out multiple branches simultaneously in separate directories without switching the main working directory. Super useful when reviewing PRs or working on multiple features at once.

For example, to create a new worktree for a feature branch:
git worktree add ../feature-branch feature-branch
This keeps my workflow seamless without unnecessary stashing or committing unfinished work.

Also, git commit --fixup combined with git rebase -i --autosquash is a game-changer for cleaning up commit history before pushing. It ensures that related changes are automatically grouped when rebasing, keeping the history tidy for team collaboration.

Git has so many hidden gems that make development more efficient. Curious —what’s a lesser-known Git trick that others here swear by?

Collapse
 
shaq_attack profile image
Shaquille Niekerk

Definitely saving this for future reference, Thanks for the share

Collapse
 
ngdangtu profile image
Đăng Tú

I used 5 / 10 and must say they are all good stuff. Can wait to use bisect next time. Cool article, thanks.

Collapse
 
fadekocodeit profile image
Future_Developer

Thanks for sharing 🌲

Collapse
 
ejazazim profile image
Ejaz

Very helpful indeed. Thanks for sharing.

Collapse
 
kavyasharma profile image
Kavya Sharma - DEV SCHOOL

Thanks!

Collapse
 
akhilesh_kotwal_3d4fbd33c profile image
Akhilesh Kotwal

Good to know new commands

GitHub desktop does most of the work for me

Collapse
 
kelvincode1234 profile image
Precious Kelvin Nwaogu

Very useful for me!!

Collapse
 
cc_f9f91ece754f4e626078c2 profile image
cc44599

nice!

Collapse
 
vipin_sao profile image
Vipin Sao

Extremely helpful

Collapse
 
telemetrytv profile image
TelemetryTV

nice!