WARNING: This is a quick spiel, with lots of Marie Kondo gifs incorporated..
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
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"
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.
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
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
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
Are there any git commands you wish you'd known about when you were just starting?
Top comments (10)
Great article, I would recommend looking into conventional commit spec conventionalcommits.org/en/v1.0.0/
This is great! Thanks for the share Karan :)
Glad it helped
Interactive way to learn git branching : learngitbranching.js.org/
Thanks for sharing, this is awesome!
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.That makes so much sense. Thanks for sharing!
we need more colorful posts like this! 😄
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.
I'm glad it was helpful Corey!