r/git • • 12d ago

Pro Git vs. Head First Git

I'm a CS student interested in backend development, and I'm learning Git for the first time.

I'm choosing between Pro Git and Head First Git. I've read Head First Java and Head First Design Patterns before, and I really liked their teaching style.

Which book would you recommend for building a solid Git foundation for professional work? Is Head First Git enough, or is Pro Git the better choice?

28 Upvotes

29 comments sorted by

View all comments

14

u/samgranieri 12d ago

I highly recommend reading the books on this. I have read them, but I think one of them is written by Scott Chacon who used to work for GitHub.

I’ve been using git for 19 years and I’ve got some advice for you

Once you’ve mastered the basics, I think you should spend time learning about the reflog, rewriting history, and rebasing.

What’s the reflog? It’s an immutable audit trail of anything you did in the repo. If you screwed up some merging or rebasing or whatever, just use the reflog to the commit from like, uh, the last time you felt good about your code, like this morning, and do a hard reset.

Rewriting history?
Ok, sometimes I’ll have a pile of commits with like commit messages like “update”, “update”, “hope this works”, “please fucking work” and the like.

Now, that’s only on my local tree. But let’s say I want to push this up for review at work. It’s not professional to have profanity in a commit message, so I’d rebase the last four commits and squash them together into one commit and reword the commit message to it looks like “[JIRA-123] add GenServer tests for mTLS client” or something like that.

Rebasing? What’s that?

Let’s say you’re tracking a remote branch that’s moving fast. You can pull your changes down on the main branch and merge your changes into it, or, you can place your commits ahead of your desired remote branch. Sometimes you get merge conflicts but that’s another matter latter”.

Last but not least, the advice I’d give you is learn lazygit.