git init
command is used to create repository. When you run this command, a new branch is created by Git, which is called master
. In addition to this, Git also creates a .git
directory that will store all the repository history.
Change to the folder in which you have stored your files. After that, run git init
followed by ls -a
.
$cd /home/mohit/mysite/ $git init Initialized empty Git repository in /home/mohit/mysite/.git/ $ls -a . .. css .git index.html js
After running this command, you will find that all the files inside the repository are untracked.
$git status On branch master Initial commit Untracked files: (use "git add..." to include in what will be committed) css/ index.html js/ nothing added to commit but untracked files present (use "git add" to track)
To track these files and let Git aware of them, run git add
followed by git commit
. It will bring entire files in the working directory under the tracking of Git.
$git add . $git commit -m "Initial commit" [master (root-commit) dc99c45] Initial commit 3 files changed, 4 insertions(+) create mode 100644 css/styles.css create mode 100644 index.html create mode 100644 js/app.js
You can view the commit logs by running git log
.
$git log commit dc99c45a1b78a8ce4fedd6444136905ab8d81b1b Author: Mohit Natani <[email protected]> Date: Sun Dec 27 07:23:53 2020 +0000 Initial commit