If you don’t know this about me, I am a huge fan of Git and GitHub. I’ve talked about it a fair amount on this blog and even done a presentation or two on the subject. I could sit and extol the whole shebang to you for hours on end. Instead, since it’s the end of the year, here are the bookmarks that I keep in my “Git Stuff” folder. Hopefully they’ll help you as much as they’ve helped me!
- Undo a Git merge, for when you accidentally the whole thing.
- Undo a Git pull. I use this when I fat finger where to pull it from.
- How to delete a branch both locally and on GitHub.
- Undo the last Git commit.
- Git diff against a stash is useful if you’ve got a stash that you don’t quite remember everything that changed.
- Abort a cherry-pick. This one is stupid simple, and can be applied to just about everything in Git.
- Undo an accidental
git add
. Useful if you accidentally add the wrong file in before you commit. - Force
git pull
to overwrite local. This one is obviously pretty dangerous, but it’s a quick and easy fix when you’re in a rabbit hole of confusion. - Branch from a previous commit. The idea here is that you’ve got A-B-C-D in your tree. You want a new branch that only has A-B-C. Boom. Easy.
- Reset local to match remote.
- Create a named Git stash. This is cool because it gives you a better idea of what’s in the stash and it lets you search for it better.
- Check which branches are merged into master. Also shows you which branches are not merged. This one is pretty darn useful when you’re cleaning up.
- Move the msot recent commits(s) to a new branch. I usually use this when I mess up and forget to create a feature branch before I commit a bunch of good work.
- Make Git forget aboout a previously tracked file.
Finally, here is a link that everyone should read. Every line of code is always documented by Mislav Marohnic is an awesome and easy way to see yet another reason why good source control practices are important.
BONUS
It’s Christmas, right? Here are my favorite aliases I use for working with Git:
If you decide you want to be super fancy, check out this awesome repository full of aliases.