How to Git- Create repository & Add files

In this guide, we are going to learn how to create a Git project by creating a repository directory and adding files to it. A Git repository is a directory that contains the history of a collection of files starting from a certain directory.
Let’s dive into creating repository in detail.

Create a Git repository

On the windows system, Git home directory is C:\Users\username folder. To create a new repository on the home directory inside the repository, create an empty directory. The following example will create an empty directory named “Lauyou” using mkdir command and create a file first.txt file in it.

 

Git Bash
    mkdir Lauyou
    cd Lauyou
    touch first.txt

 

Now you have a directory that contains a file. Run the git init in order to create a git repository from that directory.

Initialize Repository
    $git init
    Initialized empty Git repository in C:/Users/yp/Lauyou/.git/

 

Now we created our Git repository Lauyou. Let’s add our file to the repository.

 

Add files to Git repository

To add our file “first.txt” into the repository, use following command.

Add and Commit
    git add first.txt
    git commit -m "First Commit"

Thegit add command will add the selected changes to the staging area (also known as the index).

git commit command commits the staged changes into the Git repository.

Result
    $ git add first.txt

    $ git commit -m "First Commit"
    [master (root-commit) d675480] First Commit
    1 file changed, 0 insertions(+), 0 deletions(-)
    create mode 100644 first.txt

 

Check the status of the repository

Use the git status command, to check the current state of the repository.

 

Status
    $ git status
    On branch master
    nothing to commit, working tree clean

 

The command checks the status and reports that there’s nothing to commit to the repository.

Muhsin Yakkiparamban

Muhsin Yakkiparamban is the co-founder of Lauyou Learning. Muhsin holds Bachelor Degree in Civil Engineering from KMCT Calicut.

You may also like...