Git is all about related to the Version control system. So let’s first understand,
What is Version Control System?
It helps us to record and as well as track changes and files. As a programmer, we need to keep an eye on the history of what we had done till now so, using this, observe the history of changes in a different file, and in case we want to perform the UNDO we can go back to the previous states.
Let’s dive deep in. It is our vision system, not a programming language.
For example, here I am using Team Member Name “Harshida”,” Jay”, “Harry”, “Robot”. We need some tools that will allow us to track the changes in code or in configuration, etc.
How Version Control System Work?
Version control system might be centralized and distributed in centralized. All the team member is connected to the main server and share the details.
If our central server is down you can’t collaborate in the distributed version control system.
Types of version control system
The first step is to learn in detail about what is GIT is, let’s install GIT into our local system, so in the future, we can perform the practical operation.
How to install Git?
- Click here to open the link:- https://git-scm.com/downloads
- Download and Click on the EXE file.
During installation, a window will pop up, let’s understand some important point.
Click on RUN, And see the details, which I specified down below.
- In any place of your file system, you can press right-click and open GIT BASH OR GIT GUI.
- GIT BASH is a special application for windows, which provides the possibility to use the git command line. It is popular on Linux or MAC. Shell is used to interfacing with the operating system.
- GIT GUI is provided a graphical user interface to create a new repo, clone repo, commit, and so on.
- GIT LFS (Large file support) is an extension that reduces the impact of large files in your repository by downloading relevant versions. It will download huge files only when you will need them.
- File with the extension .sh as a shell script that is used in many variations of UNIX-like systems.
Select your editor. Click on Next, Next until you reach the Install. Keep all the default setting as it is.
How to check Git Version?
Open your cmd, and write the code as shown in the image below.
How to open Git Bash?
- Open any folder which you want to open in GIT Bash.
What is GIT? Why Git?
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Git does not store differences in files. It stores links to the snapshot of the changed file.
In case the file was not changed Git does not store this file AGAIN. Instead, it stores a link to the previous files that were stored.
Let’s understand by example,
- A group of people (“Harshida”,” Jay”, “Harry”, “Robot”) on the same project, and every developer has a COPY of the repository to work independently.
- Here every developer can modify the files and save them.
- Every developer makes a change and gives the version name, and at the end of the version name let’s say “Version-Final.”
- Imagine Harry made some changes but still, it is not visible to all (Harry’s Version name “v2”). To make his changes visible to all he should send them to the MAIN repository. Other team members will be able to pull the changes to their repository.
- What is that mean?
- Harshida, can pull the changes from the main server and get the changes done by Harry. So, Harshida has a version of TWO/V2.
What is GIT repository?
In a new project, we add files, update, delete. Now to keep information about all of this, the Git repository helps us a lot. If you delete the repository, we don’t lose the existing files but we lost the history of the project. In short, it is the folder, which has files with the current state and history.
How to create GIT repository?
Login with your account details in github.com and follow the steps as shown in the images down below.
Where Git repository save our data?
Saving data into the local machine: – The repository can be local means you can save on a local machine like your computer.
Saving data into Cloud: – If it is remote then history saved on the remote server, which means cloud, such as Git Hub, Git Lab, and others.
Here the user Can clone the project and work in his local system without affecting the remote server.
How to create clone using GitHub?
You can clone this repository using,
Here I am using HTTPS.
Copy the URL.
Open the command prompt and perform the operation as shown below.
How to check your repository is connected with any remote repository?
git remote -v
If nothing is shown in the terminal means you have to connect with the remote.
git remote add origin https://github.com/.......
How does the GIT Life cycle work?
- User/ Harshida has created one file in the folder. The status of This file is: – Untracked.
- The reason behind “Untracked”, because as a developer I have just created.
- Now if you add the file into the repository then the status changed from Untracked->Staged. (using Git add).
- Now Git knows about the about file and changes in it. Information about such changes is placed in the file with the name INDEX. When you change files or a set of files, you add those files to the index.
- But the changes are not yet recorded in history. You need to perform “committed.” This is the state when the changes are saved to the local repository.
- Using “Git commit”, all files as saved and create a unique identifier in the history.
- One of the important points you need to note out if the files got deleted afterward because we have it in history and we are able to restore it. But “Untracked” file will not be saved with this operation.
- Git Commit works only for Staged file.
- To share all the files with the team member our changes must be visible to the remote repository.
Inform GIT WHO YOU ARE.
How team member access the my file?
“Git push”: – the state of the local repository to the Remote Repository. Then, all the team members will see the changes I made in my code.
How to check the status using Git?
We have the git command using it we can check the file state.
What is the use of “git diff” command?
Now open cmd with a specific pathname.
You can see the changes we had made in our file using the “git diff” command.
Imp point you need to point out is, “git diff“, shows only the changes which are unstaged.
When we specified the “git status“, the changes are not staged. So we need to stage it by specifying “git add“.
Now GIT recognizes the changes we made and now ready to commit them.
git status -s git status --help
To check which is added and which is not.