How to Create Git Repo for Existing Project Updated
How to Create Git Repo for Existing Project
In this tutorial, nosotros will learn How to Create Git Repository . Nonetheless, before you proceed with this tutorial it is very important that you lot have gone through the previous set up of tutorials on GIT here:
What is a Git Repository?
The purpose of Git is to manage a project, or a set of files, equally they change over fourth dimension.Git stores this information in a data structure called a repository . In short Git Repository is a collection of all project files along with their history . Information technology is a virtual storage of your project where you go on all the resources/files of the project along with a special folder called .git. The .git folder in a git repository is used by GIT programs to store information near the repository like Logs , Position of Head , and more. It allows you lot to save versions of your code, which can exist accessed, tracked, and managed.
At this commodity, we don't know much about these terms and hence we will keep our discussion to a minimum about the .git folder. For the time being, just remember that every GIT repository will have a hidden .git binder to enable GIT programs to track changes in the repository.
Different ways to Create Git Repository
Nosotros can Create Git Repository using i of the three approaches enlisted below:
- Create a bare repository
- Initialize repository in an existing project directory
- Clone a remote repository from Github
We'll be using Git command line tool to create repositories and also for learning all the Git operations in this serial of tutorials. Use of Git command line tool volition help you get familiar with the GIT Commands . Using Git command line tool gives you more flexibility than Git Clients or Git GUIs considering they provide only a subset of GIT Features . So, to harness the consummate ability of Git similar a pro, Git command line tools are the recommended way to utilize GIT.
So, let'due south get started and see how we can create a Git repository in the three ways mentioned in a higher place. The very first thing is to find the Git command line tool on the system. I promise y'all have already gone through the Git installation process described in the tutorial here:
Create a Blank Git Repository
Creating a Bare Git Repository for a new project is three-footstep process:
- Create a New Project/Folder
- Scan to New Project
- Initialize Git Repository for the Project
Once y'all have Git installed, just search of git cmd in your system search bar. You will go the Command line tool listed every bit shown in the below image.
Note : that this is Windows 8 System search bar, you will have a unlike ane based on the Bone yous have.
Open up the Git command line tool, y'all will run across a command line window open up as shown in the image below.
Pace one: Create a New Project/Folder - Now that we have our command line tool open, let us create a project folder . Creating a project folder with a adept proper noun is very important. If yous have a Good and Relevant name of your project information technology will become easier for you to identify and relate to the project when yous come back to it in the future.
Note : Usually people create a Root Project folder with the visitor name similar toolsqa, amazon, flipkart, etc, and within this root folder they go on all the different projects of the same company.
Command to create a folder on a Windows and Mac system is mkdir <folderName>
. Where folder name is the projection name. Let us proper noun our first project LocalGit . With this proper name, the control becomes: mkdir LocalGit
Navigate to this folder past using the command cd LocalGit
, both on Windows and Mac systems.
At present yous are inside the repository folder where we'll create our Git repositories using the iii approaches mentioned higher up.
Bare Git repository means an empty directory with simply a hidden .git folder. Let united states of america name the project as BareGitRepo . Ensure that you're in the LocalGit folder before proceeding with following steps. Enter command mkdir BareGitRepo
.
Annotation : So now yous accept your Root Folder (LocalGit) ready and within that the Project (BareGitRepository)
Step 2: Browse to New Project - Navigate to the project created in the previous step using the command cd BareGitRepo
.
Step 3: Initialize Blank Git Repository for the Project - Enter the command git init
this command is used to Create Git Repository. Consequently, the execution of this control creates a hidden .git folder therein. Or in other words, an empty Git Repository is initialized . You'll find a bulletin stating that an empty Git repository is created.
Note : git init is a standard GIT command and it initializes the directory with a .git folder used for tracking versions of project artifacts.
Let united states of america view the contents of the newly initialized Git repository by executing the command dir /ah
.
After the execution of dir , you volition come across empty projection folder equally expected from a Bare Git repository . You lot can now add projection files to this repository and they'll be tracked by GIT.
However, if you want to see the .git folder being reported in command line use the control dir /a:hd
. This will bear witness hidden folders in the directory and you will notice .git folder at that place.
Create Git Repository for an Existing Project
Nosotros'd also like to track an existing project by using Git. In this example, we'll initialize a Git repository in an existing project directory. There is no rocket science in creating git Repository for an existing project, it is as same as creating a git repository for a new project with the merely difference of stride i is non required:
-
Create a New Project/Folder - Browse to Existing Project
- Initialize Git Repository for the Project
Step two: Browse to Existing Project - Navigate to the directory containing your projection artifacts. In this case, let us consider that the proper name of the project is SampleProject at the location C:\Users\admin1\LocalGit\SampleProject , move to a similar location on your system. One tin view the content of the directory by using the command dir
.
Annotation : I already accept few files in the SampleProject for a demo purpose, so it is not an empty binder.
Step three: Initialize Git Repository for the Projection - Initialize the git repository in this project by using the same control used while creating a blank repository i.e. git init
.
View the content of the directory and note that a .git binder has been created therein.
Afterwards Git initializing, the project is tracked past GIT .
Cloning a Remote Repository from GitHub
When you lot desire to contribute to an existing projection hosted on GitHub or a similar online Git service provider, you lot've to Clone their repository from the remote server like Github, GitLab, etc. For case, the remote repository of Apache POI (Java library to read from and write to Excel files) is hosted at https://github.com/apache/poi
Definition of word Clone in the context of Git is to create a local copy of the Remote repository. In this case, remote Repository is hosted at https://github.com/apache/poi and nosotros will Clone it on our local system.
Here are the steps to clone (download and track the changes) this repository.
Step ane: Fetch and copy the URL, every bit mentioned in the image below, of the Apache POI repository at GitHub . That is, https://github.com/apache/poi.git
Stride ii : In Git CMD, navigate to the folder for storing all the Git repositories locally. That is C:\Users\admin1\LocalGit in this case.
Pace 3: Create a directory called RemoteCloneRepo to store the source code of Apache POI repository locally by using the command mkdir RemoteCloneRepo
Navigate inside this newly created directory past using the control cd RemoteCloneRepo
Step 4 : To clone the repository, enter the command git clone https://github.com/apache/poi.git
Note : git clone <repoURL>
is a standard GIT command to clone an existing remote repository.
Step v: Cloning a repository depends on the size of the repository. Usually, information technology takes a while for a large repository. Yous'll take to wait until all the files are checked out.
Now you can brand changes to the repository. Git will runway all the changes.
In this tutorial, we looked at the three means to create a Git repository. In the adjacent tutorial, we'll acquire about the typical Life-Bicycle of files in a Git repository. We will also learn almost different Git commands that will aid united states movement our Git repositories into different stages of a typical Git life-wheel.
How to Create Git Repo for Existing Project
Posted by: villarrealtilk1949.blogspot.com
0 Response to "How to Create Git Repo for Existing Project Updated"
Post a Comment