Source: http://www.liaoxuefeng.com/
Here only the local part.
Install on windows
- download: https://git-for-windows.github.io, mirror available;
- run 'Git Bash';
# Set name and email.
$ git config --global user.name "Your Name"
$ git config --global user.email "email@example.com"
Establish repository
# Making an empty directory
$ mkdir learngit
$ cd learngit
# display current working directory
$ pwd
# Making the current directory a Git-managed one. Don't change the directory
# .git (version repository)
$ git init
Initialized empty Git repository in /Users/michael/learngit/.git/
$ ls -ah # list hide folders
Add files into the repository
# Add files into current working directory
$ git add readme.txt
# Add annotations of this submission
$ git commit -m "wrote a readme file"
# Submit multiple files at one time
# Actually, *add* operation is to submit the file to *stage* (working area,
# store the files currently worked on) in the repository (/.git), and
# *commit* will move the ones from *stage* to current branch (git will
# automatically create one named *master* for us (*HEAD* is a pointer
# pointing to master).
$ git add file2.txt file3.txt
$ git commit -m "add 3 files."
# Check the differences between the most recent file in the repository and
# the one in stage.
$ git diff HEAD -- readme.txt
Change the files in the repository
# Check current status of the file
$ git status readme.txt
# Check the changes
$ git diff readme.txt
# If the changes agreed
$ git add readme.txt
$ git commit -m "One change"
Version swap
# Check history changes, note that a more clear time line could be seen in GUI
$ git log
$ git log --pretty=oneline
# Swap back to the last version, HEAD^^ denotes the penultimate version, and
# HEAD~100 denotes the last 100th version
$ git reset --hard HEAD^
# Recover recent versions
# If the command window is not closed after swapping back, the newer version
# could be recovered using the commit ID (first few numbers are enough; you
# could look up to it at the log checked before)
$ git reset --hard 3628164
# If the command window has been closed after swapping back, the command below
# could trace command history, thus you could find the commit ID of the newer
# file.
$ git reflog
# Back to the version for most recent *add* or *commit*
$ git checkout -- test.m
# Fetch the file most recently submitted to *master* to *stage*, then repeat
# line above.
$ git reset HEAD test.m
Deletion
# Delete the file directly in the working area
$ rm test.m
# Current status: but the file is not removed from repository
$ git status
# Delete the file from repository
$ git rm test.txt
$ git commit -m "Confirm deletion"
# Or cancel the deletion
$ git checkout -- test.txt