4 * Tell Git who you are:
6 $ git config --global user.name 'User Name'
7 $ git config --global user.email 'user@email.com'
9 * Customize the user interface:
11 $ git config --global core.editor nano
12 $ git config --global color.ui auto
17 * Create a local repository from a public repository at `$URL`:
21 * Stage a (possibly new) file (or files) for the next commit:
25 * Remove a file (or files) with the next commit:
29 * Commit any local changes to the local repository:
31 $ git commit -a -m "$MESSAGE"
33 * Push any local commits to a public repository (e.g. `origin`):
40 * Update your local view of a public repository (e.g. `origin`):
44 * Merge new commits from another branch (e.g. the `origin/master`
45 branch tracking the `master` branch of the `origin` repository):
47 $ git merge origin/master
49 * Mark conflicts as resolved:
53 * Instead of merging `origin/master` into your local branch, you can
54 rebase your local branch onto `origin/master` (useful options:
57 $ git rebase origin/master
62 * Compare the current working directory to the staging area:
66 * Compare the staging area to the last commit:
70 * Compare the current working directory to the last commit:
77 * Check your local state:
81 * View past commits (useful options: `--oneline`, `--graph`,
82 `--decorate`, `--stat`, …):
86 * Who wrote this line, and what were they thinking?
91 Recovering old versions
92 =======================
94 * Undo local changes to `$FILES` since the last commit:
98 * Checkout `$FILES` as they were during `$COMMIT`:
100 $ git checkout $COMMIT -- $FILES
102 * Create a new commit backing out changes made by an old commit:
106 Setting up a repository
107 =======================
109 * Create a new repository in the current directory:
119 $ git push --tags origin
121 * Incorperate the tags into any releases. For example, the Git
122 project extracts [version information][git-version-gen] when you
123 [compile the project][git-makefile]. Most Python projects just
124 increment `package.__version__` by hand
125 (e.g. [pygit2][pygit2-version]).
130 * What branch am I on? What other branches are there?
134 * Make a new branch (e.g. `some-feature`):
136 $ git branch some-feature
138 * Change the current branch (e.g. to `some-feature`) and update the
139 staging area and working directory:
141 $ git checkout some-feature
146 * List configured remotes (URL nicknames):
150 * List configured remotes with push/pull URLs:
156 $ git remote add $NAME $URL
161 * Squash new changes onto the most recent commit:
163 $ git commit --amend …
165 * Move the current branch to `$COMMIT` without touching the staging
166 area or working directory:
170 * Move the current branch to `$COMMIT` while also resetting the
171 staging area and working directory:
173 $ git reset --hard $COMMIT
176 [git-version-gen]: http://git.kernel.org/cgit/git/git.git/tree/GIT-VERSION-GEN
177 [git-makefile]: http://git.kernel.org/cgit/git/git.git/tree/Makefile
178 [pygit2-version]: https://github.com/libgit2/pygit2/blob/master/pygit2/version.py