๐Ÿ”ฅ Git Hot Tips

๐Ÿ”ฅ Git Hot Tips

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.

`git add -p`

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.

`git log -5 --pretty --oneline`

View your last 5 latest commits each on their own line.

๐ŸŸ @luclemo

`git shortlog -sn`

Quickly get a list of contributors and see how many commits each person has.

๐Ÿ‘ @csswizardry

`git log --all --graph --decorate --oneline --simplify-by-decoration`

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

`git checkout pr/123`

Quickly check out a remote for pull request review. You'll need to set it up like this.

๐Ÿค˜ @linclark

git diff --shortstat "@{0 day ago}"

See how many lines of code you have written today.

๐Ÿ’ƒ @innovati

`git checkout -`

It's like the jump button on your TV remote - jump back to to your last branch.

๐Ÿ’† @everyone

`git reset --soft HEAD~3`

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.

๐Ÿ‡ท๐Ÿ‡บ @dan_abramov

`git reflog`

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.

๐Ÿ˜ฑ @davidnormo

`git stash, then git stash pop`

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

`git log -S puppy`

Search the commit history for the word puppy and display matching commits.

๐Ÿš€ @chrisrockwell

`git latest = for-each-ref --count=30 --sort=-committerdate refs/heads/ --format='%(`refname:short)'

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.

๐Ÿ”ฅ @wesbos

`git config --global help.autocorrect -1`

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.

๐Ÿ”ฅ @wesbos

`git commit --amend`

Great for squashing staged files into your last commit.

๐Ÿ™ @carlosperez

`git cherry-pick [hash]`

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.

๐Ÿณ @jonalvarezz

`git remote update --prune`

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.

๐Ÿ‰ @mourawaldson

`git rebase -i HEAD~4`

Interactive rebase allows you to pick and choose which commits you can pick, squash, reword, edit, or fixup

๐Ÿ˜Ž @Stephn_R

`More?`

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!

Edit on Github

Syntax Podcast

Hold on โ€” I'm grabbin' the last one.

Listen Now โ†’
Syntax Podcast

@wesbos Instant Grams

Beginner JavaScript

Beginner JavaScript

A fun, exercise heavy approach to learning Modern JavaScript from scratch. This is a course for absolute beginners or anyone looking to brush up on their fundamentals. Start here if you are new to JS or programming in general!

BeginnerJavaScript.com
I post videos on and code on

Wes Bos ยฉ 1999 โ€” 2024

Terms ร— Privacy Policy