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 in `$branch` (e.g. `master`) to a public
34 repository (e.g. `origin`):
36 $ git push origin $branch
41 * Update your local view of a public repository (e.g. `origin`):
45 * Merge new commits from another branch (e.g. the `origin/master`
46 branch tracking the `master` branch of the `origin` repository):
48 $ git merge origin/master
50 * Mark conflicts as resolved:
54 * Instead of merging `origin/master` into your local branch, you can
55 rebase your local branch onto `origin/master` (useful options:
58 $ git rebase origin/master
63 * Compare the current working directory to the staging area:
67 * Compare the staging area to the last commit:
71 * Compare the current working directory to the last commit:
78 * Check your local state:
82 * View past commits (useful options: `--oneline`, `--graph`,
83 `--decorate`, `--stat`, …):
87 * Who wrote this line, and what were they thinking?
92 Recovering old versions
93 =======================
95 * Undo local changes to `$FILES` since the last commit:
99 * Checkout `$FILES` as they were during `$COMMIT`:
101 $ git checkout $COMMIT -- $FILES
103 * Create a new commit backing out changes made by an old commit:
107 Setting up a repository
108 =======================
110 * Create a new repository in the current directory:
120 $ git push --tags origin
122 * Incorporate the tags into any releases. For example, the Git
123 project extracts [version information][git-version-gen] when you
124 [compile the project][git-makefile]. Most Python projects just
125 increment `package.__version__` by hand
126 (e.g. [pygit2][pygit2-version]).
131 * What branch am I on? What other branches are there?
135 * Make a new branch (e.g. `some-feature`):
137 $ git branch some-feature
139 * Change the current branch (e.g. to `some-feature`) and update the
140 staging area and working directory:
142 $ git checkout some-feature
147 * List configured remotes (URL nicknames):
151 * List configured remotes with push/pull URLs:
157 $ git remote add $NAME $URL
162 * Squash new changes onto the most recent commit:
164 $ git commit --amend …
166 * Move the current branch to `$COMMIT` without touching the staging
167 area or working directory:
171 * Move the current branch to `$COMMIT` while also resetting the
172 staging area and working directory:
174 $ git reset --hard $COMMIT
177 [git-version-gen]: http://git.kernel.org/cgit/git/git.git/tree/GIT-VERSION-GEN
178 [git-makefile]: http://git.kernel.org/cgit/git/git.git/tree/Makefile
179 [pygit2-version]: https://github.com/libgit2/pygit2/blob/master/pygit2/version.py