Table of Contents
In the article understanding git terminology, we explained the repository (repo) and types of the repository with examples. In this article, we will run some commands and look into how repositories are managed.
How to create repo/project.
Create repo through CLI
Install Git in Linux
In order to create the git repo in your system. Firstly you need git package , you can install the package by using the following command in Ubuntu
sudo apt install git
Create an empty folder
Create an empty folder and this folder will be top level working directory for your repository. After creating an empty folder enter into that folder. See the following example I create demo2 and then changed the directory to demo2.
foofunc@ubuntu21:~/experiments$ mkdir demo2 foofunc@ubuntu21:~/experiments$ foofunc@ubuntu21:~/experiments$ cd demo2 foofunc@ubuntu21:~/experiments/demo2$
Git Init
To initialize the git repository you have to execute git initializae command in your top-level directory. The command will create a .git directory which contains all the metadata of the git repository. Use the following command to create the repo
git init
After running git init command you have successfully created a git repository in your system. See the below snapshot after running the command you will the similar output.
Creating remote repo
For creating a remote repository I suppose you have an account on any of these platforms GitHub, GitLab, and Bitbucket, etc. In this tutorial, I will be using GitLab in this tutorial however creating a project has kind of similar procedure in the mentioned platform.
Step 1: Open the browser and log in to your GitLab account. You will see the below mention page after your login. Click on the New project
Step 2: After clicking on the New Project you will see the below-mentioned page. According to your use case click on the option. In my case I wanted to create a blank project therefore I clicked on Create blank project.
Step 3: Now you will see the form like in the below snapshot fill the form and you can also set the visibility (you want the project to visible to public or only in private you can assign access to the explicit user) and then Create project
Result: Now you have your project as I have entered project name demo1 you can see the project is ready.
Clonning the remote repo
In the last section we have created remote repo now we can clone (copy) this repository in our local system and start working (adding new file and folder etc ) in this project. In the snapshot you can see that after clicking on Clone button you see that two URLs, under Clone with HTTPS option copy the URL and use this with the command.
See the following command to clone the repo.
Command syntax
git clone <Clone with HTTPS URL>
Command Example
foofunc@ubuntu21:~/experiments$ git clone https://gitlab.com/func-foo/demo1.git
After running the command you will see the following output shown in the picture. If you have chosen for the private repo then command prompt will ask for username and password.