This tutorial provides an overview of How to Set up a Repository under Git Version Control. This resource will walk you through for following topics:
- Create a Git Repository for New Project
- Create a Git Repository for Existing Project
But before moving forward, lets first understand about Git Repository.
What is a Git Repository?
The purpose of Git is to manage a project, or a set of files, as they change over time. Git stores this information in a data structure called a repository. Git Repository is a virtual storage of your project where you keep all the resources/files of the project. It allows you to save versions of your code, which can be accessed, tracked and managed.
Create a Git Repository for New Project
Creating a new Git Repository is three set process:
- Create a New Project/Folder
- Browse to New Project
- Initialize Git Repository for the Project
Step 1 Create a New Project/Folder
1) Start the Command Prompt by typing cmd in the Windows Search.
Note: Same task can be done on GitBash, so if you wish to use the it, open the Git Bash.
2) Navigate to desired folder where you would like to create a new project. cd space folder_path is the command which is used to navigate to the folder. In this tutorial, I am creating a new project in C drive, so I used cd c:/
Note: If you wish to create a new project at deeper in C drive, command will be cd c:/folderName/folderName
Notice the Output:
Now execution is on C drive, earlier it was on c:/Users/Lenovo
3) Create a new directory/folder for the project. mkdir is the command to make a new directory.
Note: In case you have space in the folder name, always use double quotes for folder name. Otherwise mkdir Git_Tutorial also can be used to create a folder with no space.
4) Folder with same name will be created under the mentioned path.
Step 2 Browse to New Project
1) As mentioned above to navigate, the command is cd folder path. We already are in C drive, so now command will be cd Git Tutorial.
Note: In case you have restarted the Command Prompt, the command to navigate to newly created project is cd c:/Git Tutorial.
Step 3 Initialize Git Repository for the Project
1) To create a New Git Repository for the project now you’ll use the git init command. The word init means initialize. This command will create a Git Repository in the current directory. This is the one-time command you use during the initial setup of a new repository.
Note: Git does not care whether you start with an empty directory or if it contains already files.
Notice the Output:
Initialized empty Git repository in c:/Git Tutorial/.git/
Initialized empty Git repository in c:/Git Tutorial/.git/
2) Executing git init command will create a new .git sub directory in current working directory. This will also create a new master branch.
Note: Every Git Repository is stored in the .git folder of the directory in which the Git repository has been created. This directory contains the complete history of the repository.
Create a Git Repository for Existing Project
There is no rocket science in creating git Repository for existing project, it is as same as creating a git repository for a new project with the only difference of step 1 below:
Create a New Project/Folder- Browse to Existing Project
- Initialize Git Repository for the Project
0 comments:
Post a Comment