# initialization
git init                                            # init a repo
git clone                                           # clone from an existing repo

# local
git add <file>                                      # add file to index (working tree -> index)
git rm --cached <file>                              # remove file from index
git rm <file>                                       # remove file from both index and working tree
git commit                                          # commit index to repo (index -> repo)
git reset HEAD <file>                               # copy from repo to index (index <- repo)
git co <file>                                       # copy from index to working tree (working tree <- index)
git co HEAD <file>                                  # copy from repo to both index and working tree (working tree <- index <- repo)

git tag <tagname>                                   # add a tag
git show <tagname>                                  # show log of commit <tagname>

# log and diff
git log                                             # show log
git diff                                            # show diff between working tree and index
git diff --cached                                   # show diff between index and repo

# branching
git br <branchname> [start-point]                   # add a new branch <branchname> pointing to [start-point]
git co <branchname>                                 # switch to branch <branchname>
git co -b <branchname> [start-point]                # add and switch to a new branch <branchname> pointing to [start-point]
git merge <commit>                                  # merge <commit> with current branch (<commit> can be a branch)
git rebase <commit>                                 # rebase current branch into <commit> (<commit> can be a branch)

# remote
git remote add <name> <url>                         # add a remote repo
git remote rm <name>                                # remove a remote repo
git fetch <repo>                                    # fetch from repo
git fetch <repo> <branch>                           # fetch remote <branch> from repo to local <branch>
git fetch <repo> <remote-branch>:<local-branch>     # fetch <remote-branch> from repo to <local-branch>
git pull <repo>                                     # fetch and merge (syntax similar to fetch)
git push <repo>                                     # push to repo (syntax similar to reversed fetch)

# stash
git stash                                           # save current modification to stash
git stash list                                      # list all stashes
git stash apply --index [stash]                     # apply a stash (restore modification), defaults to top
git stash drop [stash]                              # drop a stash
git stash pop --index [stash]                       # apply and drop
git stash branch <branchname> [stash]               # add and switch to a new branch <branchname> using [stash]

# rollback
git reset --hard <commit>                           # reset HEAD to <commit>, with clean index and working tree