Getting Started With Git Repository - Git Tutorial - 3

Getting Started With Git Repository - Git Tutorial - 3

In this tutorial we will learn how to create a local repository, add files on git repository, check the current status of your git repository, how to commit (Data safely stored in your database). Repository in Git is often referred to as a folder or folder where git stores all the files. It can store the files on the web i.e. remote repository (GitHub) or on the local system.

What is Git Repository???

Whenever we start a project, we will need to store all files in a repository. So let's start by first creating a repository. We recommend working in a separate, dedicated path for all of your work. Git stores this information in a data structure called a repository. A git repository contains, among other things, aset of commit objects.

Start Git on any project :

Let's go to create a git repository on your machine. If you are on Windows then go to Command Prompt/Power Shell, if you are on Linux or Mac then go to Terminal.

Go to your desktop by :

$ cd desktop

Create a folder named project :

$ md project

If you see your desktop then you will find a folder named project.

Now go to the folder by :

$ cd project

Now let's initialize a Git repository on this folder :

$ git init

This command will Create a new subdirectory called .git on your project folder. 

If you go to your folder then you will see a folder named .git 

Now your project is empty, but you initialize a Git repository on this folder.

Let's check your git status on this folder by :

$ git status

You will get a output like this :

On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)

Let's create a file on this folder :

$ touch file.txt

Windows doesn’t have a touch command. For windows you can create a file with echo command, like this :

$ echo > file.txt

Now check again Git status :

$ git status

You will get a output like this : 

On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        file.txt

nothing added to commit but untracked files present (use "git add" to track)

 Let's add this file on your git repository :

$ git add file.txt

Now let's your first git commit :

$ git commit -m "First Commit"

You will see a output like this :

[master (root-commit) dd566d6] First Commit
 1 file changed, 1 insertion(+)
 create mode 100644 file.txt

Now again check the current status of git :

$ git status

You will get nothing to commit, cause you make no changes on your file.

Let's check some change on your file :

$ nano file.txt

Now add something here ans save it.

On windows nano command may not work, you can edit it manually.

Let's check again the status :

$ git status

You will get a output like this :

On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   file.txt

no changes added to commit (use "git add" and/or "git commit -a")

Now add this changes on your git :

$ git add file.txt
$ git commit -m "Second Commit"

If you want to add every file in the current directory, you can simply do it by git add .

After you have created several commits, or if you have cloned a repository with an existing commit history, you’ll probably want to look back to see what has happened. The most basic and powerful tool to do this is the git log command. 

$ git log

You will get a output like this :

commit fc8c0d9575df2570021e2945fbfb57be72f7148f
Author: Talha F <[email protected]>
Date:   Wed Feb 26 22:38:34 2020 +0600

    Second Commit

commit a551aa2a4a1df7ad5cacb8f4b59bf1d06f8e7768
Author: Talha F <[email protected]>
Date:   Wed Feb 26 22:29:56 2020 +0600

    First Commit

Cool !!! Now you have a Git repo in your machine. In the next tutorial we will leran, how to share your code on GitHub.

Hashtag :
Share On :

Except where otherwise noted, content on this site is licensed under a CC BY-NC-SA 4.0 .