Edit: GitBook has changed significantly since I first wrote this answer. PDF support has been dropped, and the CLI toolchain has been abandoned in favour of a proprietary service:
As the efforts of the GitBook team are focused on the GitBook.com platform, the CLI is no longer under active development.
In mid-2019 mdBook is a good option, though it doesn't natively support PDF. If you have Rust and Cargo installed you can simply
cargo install mdbook
to get started.
Original answer:
This is exactly what GitBook is designed for:
GitBook is a command line tool (and Node.js library) for building beautiful books using GitHub/Git and Markdown (or AsciiDoc).
It supports PDF output out of the box, as well as online publishing on its own web platform.