Git is a very useful tool for version control. It is very easy to get started and having full documents.

The basic idea is creating a snapshot of the files inside a directory (say  the directory name is code). To INITIATE the git

$cd code
$git init

Then we can found .git inside /code folder, which stored the image. However, a snapshot does not exist yet.

When there is any change, say, updated codes, then we can STAGE the change by

$git add -u

the option “-u” is for all changed files and deleted files. After staged, the snapshot is NOT created. To create a snapshot, we COMMIT the stage by

$git commit -m "comments"

Now we have the snapshot. To see the history

$git log --oneline --decorate --graph

OK. Now, since the .git stored the image under the same folder, if any things happened to that folder, say bad section, or even broken hard disk, everything lost. Thus, it is better to save the repository into other place, say, other directory, server, external hard disk.

first, go to the parent directory and create a BARE repository

$cd ..
$git clone --bare code XXX.git

Then,  we have the XXX.git,  copy or move it  to a new place. Then we need to LINK that file to the directory.  In side the code folder

$cd code
$git remote add origin repository_location/XXX.git

Now, to check that,

$git remote -v

After taking a snapshot, we have to update the XXX.git by PUSH

$git push

if we just want to push a branch,

$git push origin local_branch:remote_branch

Other people can use the repository XXX.git by

$git clone repository_location/XXX.git

OK, i think that is enough.