Create Our First Local Git Repository
- Step-1: Use git init command to initialize a location as git repository:
$ mkdir gittest
$ cd gittest
$ git init
Initialized empty Git repository in /home/ubuntu/gittest/.git/
$ cd .git
$ ls -l
total 32
drwxrwxr-x 2 ubuntu ubuntu 4096 Sep 30 21:25 branches
-rw-rw-r-- 1 ubuntu ubuntu 92 Sep 30 21:25 config
-rw-rw-r-- 1 ubuntu ubuntu 73 Sep 30 21:25 description
-rw-rw-r-- 1 ubuntu ubuntu 23 Sep 30 21:25 HEAD
drwxrwxr-x 2 ubuntu ubuntu 4096 Sep 30 21:25 hooks
drwxrwxr-x 2 ubuntu ubuntu 4096 Sep 30 21:25 info
- Step-2: Create files in repo needed to be tracked by git and then use git add :
$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
$ echo “This is my first file” > test.txt
$ git add test.txt or git add * or git add -A
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached ..." to unstage)
new file: test.txt
- Step-3: Use git commit to finalize your changes as the last version:
$ git commit –m “This is my first git file”
[master (root-commit) e74c7da] This is my first git file
1 file changed, 1 insertion(+)
create mode 100644 test.txt
$ git status
On branch master
nothing to commit, working tree clean