Table of Content
- 1. What is version control?
- 2. Types of version controls
- 3. Why Git?
- 4. Installing on Windows
- 5. Setup
- 6. Git Basics
- 7. Conclusion
What is version control?
Version control is a system that keeps track of our files or projects.
So that we can have a reference of the changes that we made in that, particular file for future use.
It allows you to revert selected files to a previous state, revert the entire project to a previous state, compare changes over time, see who last modified something so that we can know what might be causing a problem, or what is the issue, who made it, and when with the details.
One major advantage when using a version control system is that if you do any mistakes or lose some of your files, you can easily recover them.
Types of version controls
Local version controls(VCS’s) - Programmers developed a local version control system that was based on a simple database that kept track of all the changes in the files.
RCS works based on keeping track of the differences between files in form of a patch set.
The other thing was that there was no work collaboration.
Centralized version controls (CVSS’s) - These systems have a single server that contains all the versioned files, and several users that check out files from that central place.
However, this setup had its own flaws. The most obvious is due to the single centralized server, which is the main area where an error can occur. If that server goes down due to any reasons, then during that particular time no one would be able to collaborate in the work or save versioned changes to the files/ repository they’re working on.
Read More: New Git Experience In Visual Studio
Whenever you have the entire history of the project in a single place, there is a high risk of losing everything in a few moments.
Distributed version controls (DVCS’s) - In a DVCS (such as Git), user don’t just check the files, but the repository, along with its full history.
Thus, if any server deteriorates due to these distributed systems where files are stored at different places, any of the client repositories can be copied back up to the server to restore it. So there is a full backup of every data.
The major difference between Git and any other version control system is the way Git thinks about its data and how it manages its data.
Git thinks of its data more like a difference between them. In Git, every time you commit or save the state of your project, Git basically remembers a picture or the blueprint of that and uses it as a reference to compare it with, what all your files look like at a moment and how it does look now at present.
This methodology makes git more efficient compared to other version control systems. So if there is no change in the files, Git doesn’t store that file again because a link to the previous identical file has been already stored once in the git.
Installing on Windows
The simple way is to go to the official Git website and click on https://git-scm.com/download/win it will be downloaded.
Git have git config command that lets you to see and update configuration variables on which Git depends.
Once you finish installing Git you should set your user name and email address.
- $ git config --global user.name “yash shukla”
- $ git config --global user.email email@example.com
You need to do this only once, because Git will always use that information for the future reference if you do anything on that system
If you want to check your configuration settings, you can use the git config --list command to see all the Git setting list.
- $ git config --list
- User.name= yash shukla
Creating a Repository
We can have a git repository in two ways.
Creating a new repository from the current working directory.
Or we can clone an existing repository from elsewhere in our system.
Initializing a Repository in an existing directory
If you have a project directory that is not yet under version control and you wish to start maintaining it with Git, then you first need to go to that project’s path or directory.
Syntax for windows -
- $ cd /c/user/my_project
- $ git init
It will create a new subdirectory with .git name which has all of your necessary repository files.
Now if you want to add existing files to version control, you should track those files and do an initial commit. You can do that first you need to type, a few git add commands to specify the files you want to track, and finally by a git commit.
- $ git add *.c
- $ git add LICENSE
- $ git commit -m 'initial project version'
Searching for Dedicated ASP.Net Core Web Developer ?
Your Search ends here.
Cloning an existing Repository
If you want a copy of an existing Git repository let’s say, a project you’d want to contribute to, just use the command git clone.
Instead of getting just a working copy, Git receives a full copy of nearly all the data that the server has. That is git will pull down all the files, branches which were present earlier.
Even if your server disk gets corrupted due to any reasons, you can get the original state of the file back from the previous clone you performed.
Syntax - git clone
Example - $ git clone https:/filename/folder/directory.
Checking file status
The main command to determine the files status is the git status command. If you run this command directly after a clone it shows the status of that file.
- $ git status
- On branch master
- Your branch is up-to-date with ‘origin/master’.
- Nothing to commit, working directory clean.
In order to track a new file, you use the command git add with the file name.
That is to save the changes which were made.
So in this blog we understood about version control systems, why we need, why git is better than others? how it helps us in managing our files/projects in repositories. We also learned about different commands of git like for saving the changes, adding the requests etc.