Git commands everyone should know
Broonix
December 30, 2016
Git is a phenomenal source control system. Having used some of its predecessors, SVN, CVS and SourceSafe, I'm always impressed at how much better things have gotten. If you have not seen Linus Torvalds talk about why he created git you should take an hour and watch it.
[Embedded video]
I do think too many developers just gloss over Git. They learn the basic commands they need day to day but miss out on some of the robust features Git has.
[Image: git.png]
So here is my list of my most used and helpful Git commands.
Most used
I checked my bash history and the list is exactly what you'd expect. These are the commands everyone knows and uses day to day:
[Code block]
Most useful
Here is my list of commands I use much less often but are very useful in a pinch.
Merging branches
[Code block]
You should be using a branching model during development. This how to merge one branch into another. --squash is optional. Using it will squash all the commits into a single commit on the target branch.
Merging remote branch
[Code block]
Not need to switch to and update a branch before merging it. Just git pull and merge the remote URL.
Squashing Commits
[Code block]
Forgot a file in the last commit? Did you do a lot of commits to track your work but want to roll them into just one commit? Use rebase to squash them together!
Cherry picking a commit
[Code block]
Want to bring over one commit from another branch into yours? Well, that's what cherry pick is for! It'll just bring over the selected commit to your branch.
Resetting your local copy
[Code block]
We've all completely fucked up our local copy at least once. It's always fixable with git. Resetting hard will drop your changes, while soft will keep them as staged files. You can also use remote URL's here to reset to the server's working copy.
Create a patch file
[Code block]
Working remotely and want to have someone look at some code for you? Send them a patch file.
Apply a patch file
[Code block]
Apply a patch to your local copy.
Stashing
This is my most used Git feature. I'd always surprised when I see people not using stashes. Stashes gives you a way to save local changes then restore them later.
This makes a few git tasks much easier. Need to switch tasks to work on something else? Stash your changes! Need to merge a branch into your local copy but you have active changes? Stash your changes! Tried an idea that didn't work out but what to revisit the code later? Stash your changes!
Saving a stash
[Code block]
Listing stashes
[Code block]
Apply a stash
[Code block]
There you have it, a few commands to add to your git toolkit.
Read the original post with all embeds and interactive content at https://rants.broonix.ca/git-commands-everyone-should-know/
Discussion in the ATmosphere