title |
---|
Git Good |
This is a starting point for mastering git, a sisyphean task no doubt. Git is a complex software, nobody is expected to master all of it, so if you have a useful tip, please share!
The git manual pages are actually very good. Start with man git
and
maybe check out man gittutorial
. Don't be shy about using man git-<subcommand>
when you don't know how to do something. If you're
curious about different ways to use git in your daily workflow, check
out man gitworkflows
.
-
Separate commits into small, logical changes. Avoid large diffs as much as possible. link
-
In a commit message, the first line is a brief what, the rest is a succint why. link
-
In commit messages, limit the first line to 50 characters, wrap the rest to 80 characters. link
I once read an interview with Linus where he said that every git command is
basically a different take on rebase
. So, if you want to get good at git
quick, learn about rebasing - the rest will follow.
- Git Book chapter on rebasing
- Ryan's tutorial (archived link)
- Rebase as an alternative to merge [video]
- Don't be scared of git rebase
- Learn git branching - awesome interactive tutorial
Git isn't perfect. These tools make it easier to work with:
- GitHub Desktop
- Magit (emacs package)
- gitgutter (vim plugin)
- fugitive (vim plugin)
Original article: How to Write a Git Commit Message
Git was originally used over email: someone would make a change to some
software, create a .patch
file, and email it to the maintainer. In the email,
the author of the patch would add an appropriate subject with a brief line about
what the patch does, and then in the body they would explain why the patch
is a good idea.
Commit messages retain this structure: the first line is a brief what, the rest is a succint why.
I guess they're really more like guidelines...
- Separate subject from body with a blank line
- Limit the subject line to 50 characters
- Capitalize the subject line
- Do not end the subject line with a period
- Use the imperative mood in the subject line
- Wrap the body at 72 characters
- Use the body to explain what and why vs. how
Originally created by David Winterbottom, this is a quick hack to make you more likely to write helpful commit messages.
Save the following as ~/.gitmessage
:
# If applied, this commit will...
# Why was this change made?
# Any references to tickets, articles, etc?
Then, add the following to ~/.gitconfig
:
[commit]
template = ~/.gitmessage