my-git

English 中文

Original post: http://ixirong.com/2014/11/19/the-way-to-learn-git/

1. What is Git?

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

The Git Wikipedia page covers Git in depth — its history, usage, and a wealth of reference material. One thing to keep in mind: the most effective way to learn is to read the documentation. Going straight to the official docs is the fastest path to mastering Git.

Since Git is a distributed version control system, how does it differ from SVN?

  1. Distributed vs. centralized — multiple full copies of the repository vs. one central copy. What happens when the central server goes down?
  2. No network required — you can do version control anytime, anywhere. Want to roll back to a previous version without network access? SVN basically can’t do that.
  3. Branching and merging are fast and cheap — nearly instantaneous, with no real overhead. In SVN, branching is essentially copying the entire codebase.

For a thorough discussion of Git vs. SVN on Stack Overflow, see Why is Git better than Subversion?

GitHub compares the two in terms of repository structure, history, and submodule support: What are the differences between SVN and Git?

2. Installing Git

Pro Git has clear instructions for installing Git on all platforms. If that feels too dense, check out Liao Xuefeng’s Git installation guide for a more approachable walkthrough.

3. Getting Started with Git

4. Branches and Tags

One of Git’s best features is how it handles branches — fast and effortless. A single command:

git branch branch-name

creates a new branch in milliseconds. But precisely because it’s so easy, poor branch hygiene can lead to a tangled mess that’s impossible to follow. I recommend reading Ruan Yifeng’s article Git Branching Strategy, which is based on the classic post A successful Git branching model. A Chinese translation is also available on OSChina: Introducing a Successful Git Branching Model.

Messy branches

5. Common Git Commands

A solid PDF reference for everyday Git commands: Git Cheat Sheet. There’s also a handy visual summary: Common Git Commands. I’ve compiled both into an XMind mind map, available on Baidu Pan (password: 6x7u) — updated periodically. Preview below:

Git XMind mind map

The most powerful command reference of all is right in your terminal: man git, man git <command>, git --help, or git <command> --help. Everything you could ever need is there.

6. Books and Resources

Added 2015-01-22

Added 2015-04-05 — git-flow tooling


Finally: once you start using Git, get comfortable with the terminal. Curious about a command? Just run git branch --help (or any other command) and let Git explain itself.