Introduction to GIT Repository
GIT Repository is a mainstay place for your code. It keeps track of all the code changes which were made. You can think of this as a form of data structure.
Whenever you make your project available for Version Controlling, you will observe that a .git folder is created inside the root directory of the project. This is the main folder where all the information pertaining to your code changes is stored. The .git folder contents are:
- hooks/: example scripts
- info/: exclude file for ignored patterns
- objects/: all “objects”
- refs/: pointers to commit objects4 files:
- HEAD: current branch
- config: configuration options
- index: staging area
Here “object” includes
- commits (a reference to a tree, parent commit, etc.)
GIT Repositories can be created on your Systems or online GITHUB is one of the most popular online sites where you can create your repositories. In this tutorial, we will see how to create your GIT repositories on your system
Types of GIT Repository
GIT Repositories are of 2 types:
- Non-Bare Repositories
Each of these repositories type has its own way of handling the work that we do.
And there is a separate way of creating each of these repositories in GIT
1. Bare Repositories
These are the repositories that don’t have any codebase or working directory in them. They only have the contents of the .git folder. Whenever you open bare repositories, below is what you will see:
As you can see in the above image, there is no code content or your files which you are tracking for your code changes.
A bare repository is used when you want to share your code among your teammates when your team is working on similar projects. That is the ideal situation to make use of the git bare repository. A clone of the bare repository is made, and changes are made in the code and pushed to the centralized bare repository.
2. Non-Bare Repository
A non-bare repository, as compared to the bare repository, has a working directory inside it. By working directory we mean a code or set of files which you are working upon
As you can see from the above image we have a file which we are tracking that is the .pdf file, and another hidden directory is created which is our .git folder. There is practically no scenario where we would use the non-bare repository in GIT. Moreover, Pushing code changes to the non-bare repository is not allowed; you would have to make some changes in the config file of GIT.
How to Create a GIT Repository?
In the previous section we had read about the bare and non-bare repositories now we will study how to create these repositories
1. Creating a non-bare repository
- Navigate to the path for the creation of the If you are a windows user, start GIT bash, and MAC users can use Terminal.
- I have navigated to the folder Non-Bare
- Run the command git init
You will get the above output and you will also observe that .git folder has been created along with the files which you wished to track
2. Creating a bare repository
Navigate to the folder which you want to create as a bare repository
- I have navigated to the Folder named bare.
- Now, I will run the command git init-bare
- You will observe that the content of the folder which you have initialized as a bare repository are as below.
The bare repository only has the folder structure of the.git folder and no working directory inside it.
In the end, we would conclude that GIT is a really helpful tool even if you are not managing your codebase but a certain set of files that are getting modified by a large number of users. It helps you in sharing, as well as knowing which user has made what changes.
GIT Repository is a mainstay place for your code where all your changes are stored in a metadata type structure. Each part of the .git directory plays an important role in managing the sanity and versioning of your code. Each type of GIT repository bare or non-bare has its own use case.
The command git init is used for creating repositories with –bare flag creating the bare repositories and the command without the –bare flag creates a non-bare repository.
This is a guide to the GIT Repository. Here we discuss the Types of GIT Repository and how to create bare and non-bare repositories. You may also have a look at the following articles to learn more –