How to Initialize a Local Git Repository

This article is specifically written for a Git section article because the focus of this article is solely on the usage of a Git utility where the main purpose is stated in the title of the article. It is specifying on how to initialize a local Git repository.

There are two scenarios which can be happened in the real situations. It is classified as both using an empty folder or a folder with the content already available. Below are those descriptions :

1. Initializing Local Git Repository in an empty folder :

It starts with creating a new folder named ‘git-folder’ and then the command responsible for initializing it will be executed as follows :

user@hostname:/var/www/html/git-testing$ mkdir git-folder
user@hostname:/var/www/html/git-testing$ cd git-folder/
user@hostname:/var/www/html/git-testing/git-folder$ git init
Initialized empty Git repository in /var/www/html/git-testing/git-folder/.git/
user@hostname:/var/www/html/git-testing/git-folder$

2. Initializing Local Git Repository in a folder consisting of files or folders.

The other situation is where the initialization of a Local Git Repository in a folder contains several files or folders which is actually a Laravel web-based application. It can be shown in the following command execution :

user@hostname:/var/www/html$ composer create-project laravel/laravel git-testing
user@hostname:/var/www/html$ cd git-testing
user@hostname:/var/www/html/git-testing$ ls
app artisan bootstrap composer.json composer.lock config database package.json phpunit.xml public readme.md resources routes server.php storage tests vendor webpack.mix.js
user@hostname:/var/www/html/git-testing$
user@hostname:/var/www/html/git-testing$ git init
root@hostname:/var/www/html/git-testing# ls -al
total 232
drwxrwxr-x 13 user user        4096   Nov 22 17:23 .
drwxrwxr-x 29 www-data user    4096   Nov 22 12:44 ..
drwxrwxr-x 6 www-data www-data 4096   Aug 30 16:55 app
-rwxr-xr-x 1 www-data www-data 1686   Aug 30 16:55 artisan
drwxrwxr-x 3 www-data www-data 4096   Aug 30 16:55 bootstrap
-rw-rw-r-- 1 www-data www-data 1380   Aug 30 16:55 composer.json
-rw-rw-r-- 1 www-data www-data 139081 Nov 22 12:44 composer.lock
drwxrwxr-x 2 www-data www-data 4096   Aug 30 16:55 config
drwxrwxr-x 5 www-data www-data 4096   Aug 30 16:55 database
-rw-rw-r-- 1 www-data www-data 572    Nov 22 12:44 .env
-rw-rw-r-- 1 www-data www-data 521    Aug 30 16:55 .env.example
drwxrwxr-x 7 www-data www-data 4096   Nov 22 16:58 .git
-rw-rw-r-- 1 www-data www-data 111    Aug 30 16:55 .gitattributes
-rw-rw-r-- 1 www-data www-data 146    Aug 30 16:55 .gitignore
-rw-rw-r-- 1 www-data www-data 1129   Aug 30 16:55 package.json
-rw-rw-r-- 1 www-data www-data 1040   Aug 30 16:55 phpunit.xml
drwxrwxr-x 4 www-data www-data 4096   Aug 30 16:55 public
-rw-rw-r-- 1 www-data www-data 3491   Aug 30 16:55 readme.md
drwxrwxr-x 5 www-data www-data 4096   Aug 30 16:55 resources
drwxrwxr-x 2 www-data www-data 4096   Aug 30 16:55 routes
-rw-rw-r-- 1 www-data www-data 563    Aug 30 16:55 server.php
drwxrwxr-x 5 www-data www-data 4096   Aug 30 16:55 storage
drwxrwxr-x 4 www-data www-data 4096   Aug 30 16:55 tests
drwxrwxr-x 36 www-data www-data 4096  Nov 22 12:44 vendor
-rw-rw-r-- 1 www-data www-data 549    Aug 30 16:55 webpack.mix.js
root@hostname:/var/www/html/git-testing# 

Based on the output above, the local Git repository has already been initiated by the creation of a folded named .git .

1 thought on “How to Initialize a Local Git Repository”

Leave a Reply