DEV Community

Cover image for Git Like a Pro: 10 Things I Regret Not Knowing Earlier

Git Like a Pro: 10 Things I Regret Not Knowing Earlier

chintanonweb on November 22, 2024

10 Git Things I Regret Not Knowing Earlier Git is a powerful tool for version control, but when you're starting out, it can feel overwhe...
Collapse
 
peter_wiersig_6119dfa1ef0 profile image
Peter Wiersig

I always used git commit --amend for fixing commit messages in point 1

Collapse
 
jlambertazzo profile image
Julien Bertazzo Lambert

Love --amend but always run into trouble amending a commit I've already pushed 😭

Collapse
 
supportic profile image
Supportic

if it's already in the origin repo and you amend something, do a force push afterwards
I would only recommend doing it in your feature branch, not main or develop where multiple people are working.

Collapse
 
itmam07 profile image
Itmam Alam

This is the recommended way! Glad you're using it

Collapse
 
cptcrunchy profile image
Jason Gutierrez

One nice little feature that isnt talked about is organizing your branches into "folders". So instead of prefixing your branch name with feature or what have you, you can create a directory for all potential feature branches.
git branch feature/my-branch-name
git branch feature/teammates-branch

Collapse
 
chintanonweb profile image
chintanonweb

added and updated! thank you!

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
asmyshlyaev177 profile image
Alex • Edited

Worth mentioning git bisect tool, it's good for finding which commit broke something.

git reflog is useful too, can undo even git reset.

Also, semantic versioning, e.g. when topic applied to commits, like feat for features, fix, have semantic release package, good to generate changelog automatically.

Collapse
 
chintanonweb profile image
chintanonweb

added! thank you!

Collapse
 
jason_brown_34dc17bd59ce1 profile image
Jason Brown • Edited

This is great. For branches though I'm a

git switch , git switch -c fan.

Collapse
 
chintanonweb profile image
chintanonweb

Thank you!

Collapse
 
filipecsweb profile image
Filipe Seabra

Great article!
BTW, it seems the flag --soft is not needed in git reset --soft HEAD~1.
Just git reset HEAD~1 will do the trick, right?

Collapse
 
chintanonweb profile image
chintanonweb

Thank you!

Collapse
 
flerick profile image
Derick Florian

Great article. I did not know about git revert! It's a personal preference but I try to avoid git stash and use work trees instead.

Collapse
 
chintanonweb profile image
chintanonweb

Thank you!

Collapse
 
yawnyoice profile image
Yawn Yoice

Well done. Concise but clear and useful

Collapse
 
chintanonweb profile image
chintanonweb

Thank you so much!

Collapse
 
benlee360 profile image
Ben Lee

Nice job!

Collapse
 
chintanonweb profile image
chintanonweb

Thank you!

Collapse
 
cherukuri profile image
Prasanth Cherukuri

Great Article and nice comments. Thank You!

Collapse
 
chintanonweb profile image
chintanonweb

Thank you!

Collapse
 
jangelodev profile image
João Angelo

Hi chintanonweb,
Top 5, very nice and helpful !
Thanks for sharing.

Collapse
 
chintanonweb profile image
chintanonweb

Thank you so much!

Collapse
 
julia_vilando_b00d202586b profile image
Julia Vilando

Ohhh

Collapse
 
jonathan_westman profile image
Jonathan Westman

I prefer to git merge --continue for completing a merge instead of writing another commit message in point 3 after adding your files.

Collapse
 
vmorais34 profile image
Vinicius Morais

wooooww man, tks for your contribution. i didn't know about this parameter. I always continue with the commit message instead use this command. Will test later

Collapse
 
abdel_az_230fbb3b787743aa profile image
abdel az

Thanks.

Very informative

Collapse
 
chintanonweb profile image
chintanonweb

Thank you!

Collapse
 
strandloper profile image
Steve Crane

I find git worktree useful. We often work on two major branches, and using worktree lets me switch between them without needing to stash work in the other.

Collapse
 
zloeber profile image
Zachary Loeber

Semantic commit/releases are so incredibly cool. Once you start releasing this way you will never want to do it any other way. Remember, as a rule you will need to avoid squashing commits when you get to this level or you will break semantic releases (it concatenates all the commit messages into one string).

Collapse
 
coleman_corrigan_2dfde4b7 profile image
coleman corrigan

also git merge-base BranchA BranchB useful when you need to find diverging point for branches

Collapse
 
hanzla-baig profile image
Hanzla Baig
Collapse
 
europatips profile image
Europa Tips

Thank you

Collapse
 
mattk profile image
mattk

No rebase?? That would be my #1