Don't you just love little tips that make you say "How did I not know that?!"?
Small incremental improvements are the way that you inch towards mastery of a topic. Every day I learn little things about web development that as a whole make me much better at my job.
This is a list of git tips โ you may know a few of them but I bet there are a few nuggets that will help you improve your workflow 1, 5 or 10%.
A big thanks to everyone who shared their tips on twitter.
Rather than git add everything or individual files, this -p will allow you to step through each change, or hunk
, and decide if you'd like to commit it. This is really handy if you have made two different changes to the same file and want to commit them separately.
View your last 5 latest commits each on their own line.
Quickly get a list of contributors and see how many commits each person has.
This one is the best - you need to see what it does visually:
https://twitter.com/innovati/status/707385937219743744
You'll never remember this one so put it in your ~/.gitconfig file under [alias]
wow = log --all --graph --decorate --oneline --simplify-by-decoration
๐ฎ @innovati and ๐ @winstonswchow
Quickly check out a remote for pull request review. You'll need to set it up like this.
git diff --shortstat "@{0 day ago}"
See how many lines of code you have written today.
It's like the jump button on your TV remote - jump back to to your last branch.
๐ @everyone
A soft reset will keep your changes but allow you to "uncommit" something.
Instead of doing a squash, Dan prefers to dial back HEAD any number of commits and then add & commit everything into a single commit.
David says it best โ "Don't worry, it's probably saved somewhere". Git reflog allows you to see every step you have made with git allowing you to retract and reinstate your steps.
Stash let's you squirrel away unstaged changes, do some work, and then apply those changes back on.
git stash will stash those changes and put them into your list โ I like to think of this as an array of changes. Now to get them back you can git stash apply but what Sam is suggesting here is that you use git stash pop
instead which will also bring back your changes, but it removes them from your stash "array". ok ๐ @sambreed
Search the commit history for the word puppy and display matching commits.
Allows you to view your latest branchces - this is helpful for when your branch names are based on bug IDs that you have a hard time remembering.
Mistype or misspell a git command? Immediately re-run the correct command. You can use -1 to 1000
to wait a full second before the command is re-run.
Great for squashing staged files into your last commit.
As long as the commit has been fetched somewhere, you can cherry pick that code in your own branch without having to merge the entire thing.
Remove local branches that have been deleted from your remote (like GitHub). You can always run git remote prune origin --dry-run
to see what will be deleted before going all in.
Interactive rebase allows you to pick and choose which commits you can pick, squash, reword, edit, or fixup
Post yours in the comment below!
Find an issue with this post? Think you could clarify, update or add something?
All my posts are available to edit on Github. Any fix, little or small, is appreciated!