GIT Tutorial | What is a Git Repository?

Backend Pro

What is a Repository?

Let's understand what exactly a repository is first and then look at Git Repository and how they are different. 

A repository is nothing but a project's folder and we can also imagine it as just a directory. It can be anything, 

  • A java project or 
  • A python project or 
  • A directory with some documents or 
  • A web project which contains HTML, JavaScript & CSS files.
It doesn't have to be a programming-specific project. 

What is a GIT Repository? 

A Repository that is under GIT Version Control is called GIT Repository. Git can convert a plain repository into a Git repository using the "git init" command. 

    The definition as per GitHub is 

A repository is the most basic element of GitHub. They're easiest to imagine as a project's folder. A repository contains all of the project files (including documentation), and stores each file's revision history. Repositories can have multiple collaborators and can be either public or private.

If you want to know more about version control read Version Control 

There are 2 ways we can create a Git Repository 

  • Create a project directory and convert it into a Git repository. 
  • Clone an existing repository from a Git server such as GitHub or GitLab or private corporate GitHub. 

How to convert an existing project directory into Git Repo? 

Now you have a project directory but it is not under any version control and you want to convert it into a Git repo so that you get all the benefits of VCS. 

It's very simple, just with one git command we can achieve this. "git init" is the command that does the job. 
git init
From the command line, you need to switch to the project directory and execute the "git init"  command, just as shown in the below image. 


This command creates a new hidden subdirectory named .git. In windows, you don't see it directly, so you have to enable it via view -> Hidden items.

The .git folder looks like the one below. It contains all the files necessary for Git VCS. 

 
At this point, nothing is tracked from this directory. You need to explicitly add & commit any new files that are added to this repository so that these files are version controlled. I am going to explain the minimum basic commands that are needed for this purpose in a different post & video. 

How to Clone an Existing Repository? 

When do we need to clone an existing repository? 
  • The repository exists on a public GIT server ex: GitHub (https://github.com/) and you want to contribute. 
  • You are working in a corporate company and your team has to collaborate and contribute. Every corporate maintains its own GIT server that hosts all projects. Hence you need to clone it and contribute. 
"git clone" is the command which does the job. When you do the clone, Git receives a full copy of the project from the server which contains project files as well as the full version control history. 
git clone <url> 

for example, if you want to clone TheBackendPro, you can do so like below:

git clone https://github.com/ulasalasreenath/TheBackendPro 

This just pulls all the data from the remote repository and creates a new directory named TheBackendPro & initializes a .git directory inside it. 

The cloned repo looks like the one below. 

Conclusion:

In this tutorial, we understood what is Git repository and how it differs from a normal repository and also saw how to initialize a repository locally and clone a repository from a remote Git server. 

Also read

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Check Now
Accept !