Git is open-source software that allows different teams to track project changes and revisions. It saves different versions of projects in a folder known as a Git repository. In this tutorial, you will learn about what a Git repository is and how to create one.
|Post On:||What is a Git Repository?|
|Post Type:||GIT Tutorial|
|Applicable For:||Freshers & Experience|
|Get Updates:||Join Our Telegram Group|
Prerequisites To Create Git Repository
To git repository creation we have to fulfill these prerequisites:
- We Need a system where any of the mentioned operating systems should be installed: Linux, Ubuntu, Mac, or Windows
- Git should be installed and configured. (Check this article to find out how to install GIT on your machine )
- A Git project set up
What is a Git Repository?
A Git repository is a powerful tool that tracks and saves the history of all changes made to the files in a project. The data is saved in a directory called .git, which is also known as the repository folder. This makes it easy to track progress and revert back to earlier versions of a file.
Types of Git Repository
There are two types of repositories based on how they’re used on a server. Those are:
Bare Repositories: If you want to share the changes that you have made with other developers, you can use a repository. However, remember that you are not allowed to modify someone else’s repository or create a new version of it based on your own modifications.
Non-bare Repositories: Non-bare repositories are user-friendly as they allow the user to create new modifications of files and also create new versions for the repositories. If any parameter is not specified during the clone operation, the cloning process by default creates a non-bare repository.
How to Cereate Repository in Git
We can create the Repository in two ways:
There are two ways of obtaining a Git repository:
- Turning an existing directory into a Git repository (initializing).
- Cloning a Git repository from an existing project.
Initialize a Repository
In order to initialize a Git repository in an existing directory, you first need to use the Git Bash terminal window to navigate to your project’s directory.
To go to the specific directory you can use the CD command below
CD [path of the directory]
Example: CD G:\git_example
After you navigate to the project directory, you can initialize a Git repository by using the below command.
After Execute this command few questions may come into your mind:
- Why git init?
- What is git init?
Now let us try to find out the answer to the above questions one by one.
Why git init?
Before we learn about the “git init” command, let’s understand why we need it. Right now, with our limited knowledge of git, we know that Git is a version control system and can keep track of changes to a file or set of files. However, git will not automatically start tracking changes to any file; We need to let git know where and what to track. This is where “git init” comes in.
If you are not used the git init command and you are inside a folder (new or existing) and open the git bash and execute the command git status.
- Create a new directory
- Change to that location in git bash using the CD command
- Enter the command git status
- hit enter
If you want to create a new directory that is a git repository, make sure the directory is empty. If the directory is not empty, you will get an error message saying it is fatal.
What is git init?
The “git init” command can be used to create a new empty git repository or to initialize an existing directory as a git repository. After the directory is set up as a git repository, any git commands can be run within it.
you have to notice two things after executing the command:
- Initialized empty Git repository in G:/git_example/.git/
If you run the “git init” command, it will create a new, hidden folder called “.git” in the same directory. This “.git” folder will save metadata for your new git repository. The default branch name for a new git repo is “master”, but during installation, you had the option to change this default branch name if you wanted to.
Note: If we run the git init a second time then it will not override an existing “.git” configuration
Leave a Reply