Create local Git repository

Let's prepare new directory with project files.

[tcoil@tcoil ~]$ pwd
 /home/tcoil
[tcoil@tcoil ~]$ mkdir my_project
[tcoil@tcoil ~]$ cd my_project/
[tcoil@tcoil my_project]$ touch hello_world.py
[tcoil@tcoil my_project]$ touch .user_settings

Initialize git tracking of git project. The .git directory will hold all the versioning changes of our project.

[tcoil@tcoil my_project]$ git init
 Initialized empty Git repository in /home/coil/my_project/.git/
[tcoil@tcoil my_project]$ ls -lart
 total 12
 drwx------. 16 tcoil tcoil 4096 Aug 20 11:07 ..
 -rw-rw-r--.  1 tcoil tcoil    0 Aug 20 11:08 hello_world.py
 -rw-rw-r--.  1 tcoil tcoil    0 Aug 20 11:08 .user_settings
 drwxrwxr-x.  3 tcoil tcoil 4096 Aug 20 11:09 .
 drwxrwxr-x.  7 tcoil tcoil 4096 Aug 20 11:09 .git

Git status command will inform us that we do not have any files in the staging zone yet.

[tcoil@tcoil my_project]$ git status
 On branch master
 No commits yet
 Untracked files:
   (use "git add …" to include in what will be committed)
 .user_settings hello_world.py
nothing added to commit but untracked files present (use "git add" to track)

In case there are some files in our project directory that we do not want to track we can add them into the .gitignore file. Versioning system will not keep track of changes in such files.

[tcoil@tcoil my_project]$ touch .gitignore
[tcoil@tcoil my_project]$ echo ".user_settings" > .gitignore 
[tcoil@tcoil my_project]$ cat .gitignore 
 .user_settings

Git status now shows that there are untracked files (and is ignoring files in .gitignore))

[tcoil@tcoil my_project]$ git status
 On branch master
 No commits yet
 Untracked files:
   (use "git add …" to include in what will be committed)
 .gitignore hello_world.py
 nothing added to commit but untracked files present (use "git add" to track)

Add all the files to the staging zone, they will be waiting there for commit. (files in .gitignore file are ignored)

[tcoil@tcoil my_project]$ git add -A

See status - the files are now staged and waiting.

[tcoil@tcoil my_project]$ git status
 On branch master
 No commits yet
 Changes to be committed:
   (use "git rm --cached …" to unstage)
 new file:   .gitignore new file:   hello_world.py

Commit the changes with message that describes what change has been done to the files in this particular version. After we commit the changes, the stagin zone becomes empty.

[tcoil@tcoil my_project]$ git commit -m "project initialization, first commit"
 [master (root-commit) e0e9d93] project initialization, first commit
  2 files changed, 1 insertion(+)
  create mode 100644 .gitignore
  create mode 100644 hello_world.py
[tcoil@tcoil my_project]$ git status
 On branch master
 nothing to commit, working tree clean

Log shows history of the commits.

[tcoil@tcoil my_project]$ git log
commit e0e9d93b426c3992b67a28b1e09c81aba20de9f0 (HEAD -> master)
Author: coil michal.vasulka@gmail.com
Date:   Tue Aug 20 11:19:04 2019 +0200 project initialization, first commit
[tcoil@tcoil my_project]$