cheet-sheet.md: Add a Git-specific cheat sheet
[swc-git-example.git] / cheat-sheet.md
1 Basic use
2 =========
3
4 * Create a local repository from a public repository at `$URL`:
5
6         $ git clone $URL
7
8 * Stage a (possibly new) file (or files) for the next commit:
9
10         $ git add $FILES
11
12 * Remove a file (or files) with the next commit:
13
14         $ git rm $FILES
15
16 * Commit any local changes to the local repository:
17
18         $ git commit -a -m "$MESSAGE"
19
20 * Push any local commits to a public repository (e.g. `origin`):
21
22         $ git push origin
23
24 Merging
25 =======
26
27 * Update your local view of a public repository (e.g. `origin`):
28
29         $ git fetch origin
30
31 * Merge new commits from another branch (e.g. the `origin/master`
32   branch tracking the `master` branch of the `origin` repository):
33
34         $ git merge origin/master
35
36 * Mark conflicts as resolved:
37
38         $ git add $FILES
39
40 Comparing changes
41 =================
42
43 * Compare the current working directory to the last commit:
44
45         $ git diff HEAD
46
47 Browsing history
48 ================
49
50 * Check your local state:
51
52         $ git status
53
54 * View past commits:
55
56         $ git log
57
58 * Who wrote this line, and what were they thinking?
59
60         $ git blame $FILES
61         $ git show $COMMIT_HASH
62
63 Recovering old versions
64 =======================
65
66 * Undo local changes to `$FILES` since the last commit:
67
68         $ git checkout $FILES
69
70 * Checkout `$FILES` as they were during `$COMMIT`:
71
72         $ git checkout $COMMIT -- $FILES
73
74 * Create a new commit backing out changes made by an old commit:
75
76         $ git revert $COMMIT
77
78 Setting up a repository
79 =======================
80
81 * Create a new repository in the current directory:
82
83         $ git init
84
85 Provenance
86 ==========
87
88 * Tag releases:
89
90         $ git tag v1.2.3
91         $ git push --tags origin
92
93 * Incorperate the tags into any releases.  For example, the Git
94   project extracts [version information][git-version-gen] when you
95   [compile the project][git-makefile].  Most Python projects just
96   increment `package.__version__` by hand
97   (e.g. [pygit2][pygit2-version]).
98
99
100 [git-version-gen]: http://git.kernel.org/cgit/git/git.git/tree/GIT-VERSION-GEN
101 [git-makefile]: http://git.kernel.org/cgit/git/git.git/tree/Makefile
102 [pygit2-version]: https://github.com/libgit2/pygit2/blob/master/pygit2/version.py