DEV Community

Cover image for Keeping your commits clean & organized, newbie edition
Allison Cortez
Allison Cortez

Posted on

Keeping your commits clean & organized, newbie edition

WARNING: This is a quick spiel, with lots of Marie Kondo gifs incorporated..
Alt Text
These are git commands I've learned along the way that I wish I would've known since day one! I hope they're helpful for anyone just getting started with git or wanting to manage their workflow a lil' better.

Editing Commits

Alt Text
I'd say, when trying to be more organized, and especially when you're working with a group of people, you really have to ask yourself one thing... DO MY COMMITS SPARK JOY? If that's not the case, these might be some useful commands for you:

// add changes to last commit and keep original commit message
git add . && git commit --amend --no-edit

// edit your last commit message
git commit --amend -m "edited commit message"
Enter fullscreen mode Exit fullscreen mode

Git Branch

Git branch basically just allows you to make a copy of your master code, and work from that copy. When you're ready, you can merge this new branch to master.

Alt Text
sidenote: Branching can been super helpful when working on a new feature or refactoring code. This way, your main branch will always have clean, working code.

git checkout -b <branch_name> // create new branch & switch to it
git checkout <branch_name> // switch to another branch
git push origin <branch_name> // push to github
git merge <branch_name> // combine branch changes to master
Enter fullscreen mode Exit fullscreen mode

CHECKS and more checks

Going back to see what you've done is always super helpful, and just a way for you to be mindful of the changes that you're making.

git log //general summary of your previous commits
git log --oneline //shows your last commit
git reflog //to see entire history i.e. any redos, rebases
Enter fullscreen mode Exit fullscreen mode

Resources

Git documentation:
https://git-scm.com/docs/gittutorial
Atlassian tutorials:
https://www.atlassian.com/git/tutorials/rewriting-history
a blogpost by Gabriel Abud :
https://dev.to/g_abud/advanced-git-reference-1o9j

Alt Text

Are there any git commands you wish you'd known about when you were just starting?

Top comments (10)

Collapse
 
karanpratapsingh profile image
Karan Pratap Singh •

Great article, I would recommend looking into conventional commit spec conventionalcommits.org/en/v1.0.0/

Collapse
 
allisoncortez profile image
Allison Cortez •

This is great! Thanks for the share Karan :)

Collapse
 
karanpratapsingh profile image
Karan Pratap Singh •

Glad it helped

Collapse
 
rndthts profile image
rndthts.dev •

Interactive way to learn git branching : learngitbranching.js.org/

Collapse
 
allisoncortez profile image
Allison Cortez •

Thanks for sharing, this is awesome!

Collapse
 
andreacanton profile image
Andrea Canton •

Thank you for sharing! I personally use git pull --rebase when I work on a shared branch (like a release branch) to prevent unwanted merge commits on the same branch.

Collapse
 
allisoncortez profile image
Allison Cortez •

That makes so much sense. Thanks for sharing!

Collapse
 
isarisariver profile image
isarisariver •

we need more colorful posts like this! 😄

Collapse
 
bearinawolfpack profile image
Corey Lynch •

That article was really useful.
I was committing again with the same message for silly things like realizing something was misspelled or had incorrect grammar.
I didn't know about amend.

Collapse
 
allisoncortez profile image
Allison Cortez •

I'm glad it was helpful Corey!