Introduction
In a previous article, I described in detail Git and GitHub and how they perform the roles of source code management and version controlling systems. Also, I described how the developers can utilize Git and GitHub in their day-to-day real-time work.
In this article, I will describe below-mentioned points below in detail.
- Steps to configure git on Windows.
- What are git clone and pull commands and how to use them?
- What are public and private repositories?
- Steps to create public and private repositories and their differences.
Note. Before going through this session, please visit my below-mentioned session related to Git and GitHub.
Introduction To Git
Let's know about Public And Private repositories
So, I need to create a new repository calledSecondRepo as mentioned in the below image. As per the below image, the red highlighted marks should be the proper inputs as mentioned by me.
There are two types of repositories called public repository and private repository as mentioned in the below image.
Public Repository
Anyone can see that repository. There is no need to get an authorized or authenticated user to this GitHub account but you will not be modify the code. To access or modify code, You have to give that user proper access to your GitHub account.
Private Repository
Here you have to choose who has to see and modify the code of this repository. If I choose the private repository then I have to select the users and give them proper access like read and update access.
Now you can see the new repository named SecondRepo is created successfully as mentioned in the below screenshot.
Let's know about the Git clone
So in my repository named SecondRepo whatever files are present here I need to take these files to my local repository. For this, I need to clone this. To clone this you need to select the code tab and there are various ways we can clone with and these are HTTPS, SSH, and GitHub CLI as mentioned in the below image.
So as of now I can use a clone type called HTTPS and using this URL under the HTTPS clone type I can take the files available in the SecondRepo repository to my local repository. So, for this I need to install an application called Git to configure this HTTPS URL because that is related to Git and GitHub.
To get this Git application just type in the search bar or Google it for Git for Windows. So, you can see a related interface as mentioned below.
I click here 64-bit Git for Windows Setup as per my system configuration and it will start downloading. I installed it on my local machine and made sure Git is installed on my machine or not, to know this you just right-click on the desktop and you can see the interface with a few Git options as below image.
- Git GUI Here
- Git Bash Here
That means Git is installed properly in my local machine. Now I need to upload my project files to the SecondRepo repository under Add File >> Upload Files as per the mentioned below image.
After that you get an interface as mentioned below and click on choose your files.
Here I added one DateDetails.cs file and after successful upload, the interface is shown below.
If you click on the date details.cs file then you can see the entire code in GitHub as below image.
The next step is to go to the Code tab and click on clone type i.e. HTTPS and copy the HTTPS URL as mentioned in the below image.
The next step is, I create a new folder called MyGitRepo on my local machine. Go to this folder right-click inside this folder and click on the Git Bash Here option as mentioned in the below image.
Then you can see an interface of Git as mentioned in the below image.
After that, you mention your HTTPS URL with the git clone command. Here git clone is the Git command. Our system can't recognize the git clone command by default and that's why I installed Git in my local machine. Check the below image.
The command is
git clone https://github.com/satyaCsgithub/SecondRepo.git
After then my Git started cloning the files in the SecondRepo repository to my local machine. Check the below image.
Also, You can check in the local machine there is a new folder created same as the SecondRepo repository name, and the files available in that repository are cloned successfully into my local machine. Check the below image.
To get the list of files and folders in my local machine using the Git command "ls" as mentioned below. Here ls is the command that gives the list of files and directories.
To check the details of the file in that SecondRepo folder check the below command as mentioned below.
Git Clone
It is the git command that is used to clone the files for the first time from our local machine.
Let's understand in details with scenario
Here one developer created one new file under the SecondRepo repository in GitHub and then clicked on the Commit new file button to save the changes. The file name is MyFile1.cs and the content of this file is mentioned below.
Here you can see the newly created file as mentioned below.
Let's know about the Git pull
Now I want to get this new file named MyFile1.cs to my local machine. For this I use a git command called git pull. This command will start pulling that new file from the SecondRepo repository to my local machine. Check the below image.
The command is: git pull
If you check the local machine then you can see that new file as mentioned below.
You can check by command as below image.
Now I want to print the content of this new file called MyFile1.cs. The command is cat MyFile1.cs. Here you can see the same content I have made changes in the GitHub account the same content is available now on my local machine.
let's update the same file with new content by clicking on the edit option. Added one line code as highlighted in the below image and then clicked on the Commit changes button.
Now my new file is updated with new changes as mentioned below.
Now I want to get the latest changes to my local using the git pull command and print the latest content using the cat MyFile1.cs command as below image.
In this way, We can get new files and updated files with new changes using the git pull command from the GitHub repo to Local Git.
Difference between Git clone and Git pull
Git Clone
- It used to get files for the first time from the GitHub repo to the Local Machine
- It is used only once
Git Pull
- It is used to get the latest changes or files from the GitHub repo to the local Git
- It can be used multiple times
Let's Understand Git Flow Using Diagram
Here GitHub is the account and there are two repositories called FirstRepo and SecondRepo. So, I want to get files from the FirstRepo repository to my local git which is available on my local machine. The git is installed on the same machine as I described earlier. Here for getting code the first time I used a command called git clone to get files from the remote repository to my local repository. There is a repository called .git is created and this is nothing but a local repository in my as per the below image.
The first time after cloning, This .git folder is in a hidden format. To make it visible just make the setting as shown in the below image.
Understanding Public and Private repositories in depth
Here I will check my public repository SecondRepo in another browser without signing in. Here everyone can see those files even without signing in or without any authentication and authorization as shown in the below image.
Here edit link is disabled so that the user can't change it without signing in and for this special permission is required with Signed In as shown in the below image.
Now I want to create a private repository calledMyThirdPrivateRepo as shown in the below image and let's see what happens.
After then you can see the interface as shown below.
Here I will check my private repository MyThirdPrivateRepo in another browser without signing in. Here you got a page not found message.
If one user called abc also signed in and wants to see the files present in that private repository but the user can't access that private repository. For this, the admin of that private repository which means who created that private repository gives permission to that abc user. Those permissions are for seeing the repository the admin will give the read permission to the ABC user and for updating the changes the admin will give write permission to the ABC user.
Summary
In this write-up, we have learned the below details.
- Steps to configure git on Windows.
- What are git clone and pull commands and how to use them?
- What are public and private repositories?
- Steps to create public and private repositories and their differences.