What is Git?
If you are new to programming you might have heard about Git, GitHub GitLab and etc... So What is Git and GitHub? Before entering into this lets clear about Version Control System.
Version Control
Version Control System (VCS) is a software that helps software developers to work together and maintain a complete history of their work.
Version control helps to product developing teams to manage changes in source code over time. Version control keeps track of every modification to the code in a special database. If any errors in a new versions, developers get older version easily and compare earlier versions of the code to help fix the error while minimizing disruption to all team members. Version control is sometimes referred to as source control or revision control.
VCS allows developers to work simultaneously. Does not allow overwriting each other’s changes. Maintains a history of every version.
Let’s see the different Version Control:
Centralized Version Control
Centralized Version Control are web-server based storage system. Central server to store all files and enables team collaboration. Collaboration and web-based version control helps to Storing and Managing code.
A Project stored in a Central location where a team of developers can clone to their local storage. This makes work in their individual copy of project. it does not affect the original copy of project. After changes with a new features can merge with the centralize storage.
There are many Centralized version control systems are available in the market. Such as GitHub, GitLab, CVS, Perforce, and SVN.
Distributed Version Control
This type of Version Control keeps a record of every changes in a project by taking snapshots. Here easily roll back to any previous version/state of a project.
These systems do not necessarily rely on a central server to store all the versions of a project’s files. Instead, every developer “clones” a copy of a repository and has the full history of the project on their own hard drive.
In words both provide source code management (SCM) and make merging and sharing code easier. We can think of Centralized version Control as a network of interconnected computers and DVCS as a single computer.
Lets deep into Git
Git is the most commonly used Distributed Version Control System. Originally created by Linus Torvalds in 2005.
Git Lifecycle
Git commands start with the keyword git. Git development environment is consisting of three sections.
Working Directory
It simply refers to the current state of files and folders inside your file system. At this point, Git doesn’t track these files.
Staging Area
Before saving any file to a repository, you have to place it in a staging area. It’s like a temporary location for your files and folders before commit. You can easily add or remove files from a staging area.
Create a Repository
By default, Git software doesn’t track each and every file on your computer. We’ve to inform Git about the specific folder that it must track.
Repository
A repository holds your actual committed files. Git stores all this information inside a hidden folder called .git. When you commit something, whatever inside your staging area is permanently saved in a repository.
You can think of a commit as a checkpoint. So basically, git compares your previous checkpoint with recent commit to only store the modified files.
Git Commands
Download and Install Git Software in Computer. Open your command prompt or terminal inside execute the below command to know the version of Git software.
$ git --version
$ git — version git version 2.21.0.windows.1You should be able to see your installed git version like: $ git — version git version 2.21.0.windows.1
Get Prakash Ramu’s stories in your inbox
Join Medium for free to get updates from this writer.
Identity
The first thing you should do when you install Git is to set your user name and email address. This is important because every Git commit uses this information, and it’s immutably baked into the commits you start creating:
$ git config --global user.name "Prakash Ramu"
$ git config --global user.email "prakashram1317@gmail.com"you need to do this only once if you pass the --global option, because then Git will always use that information for anything you do on that system. If you want to override this with a different name or email address for specific projects, you can run the command without the --global option when you’re in that project.
git init
This creates a new subdirectory named .git that contains all of your necessary repository files. At this point, nothing in your project is tracked yet.
git clone
Git clone is a command for downloading existing source code from a remote repository (like Github, for example). In other words, Git clone basically makes an identical copy of the latest version of a project in a repository and saves it to your computer.
$ git clone https://name-of-the-repository-linkThere are a couple of ways to download the source code, but mostly I prefer the clone with https way.
git add and git commit
The git add command is used to add file contents to the Staging area. This command updates the current content of the working tree to the staging area. There some options are available that can add more than one file at once.
$ git add Yavar
$ git add first-project$ git commit -m 'Initial project version'
Now we are ready to move our file from staging area to local repository. Git commit is the term used for saving changes.
Git does not add changes to a commit automatically. You need to indicate which file and changes need to be saved before running the Git commit command. The commit command does not save changes in remote servers, only in the local repository of Git.
git status
The main tool you use to determine which files are in which state is the git status command. If you run this command directly after a clone, you can see the following result.
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree cleangit branch
Branches are highly important in the git world. By using branches, several developers are able to work in parallel on the same project simultaneously. We can use the git branch command for creating, listing and deleting branches.
Creating a new branch:
git branch <branch-name>This command will create a branch locally. To push the new branch into the remote repository, you need to use the following command:
git push -u <remote> <branch-name>Deleting a branch:
git branch -d <branch-name>git push
Push operation copies changes from a local repository instance to a remote one. This is used to store the changes permanently into the Git repository. This is same as the commit operation in Subversion.
git pull
Pull operation copies the changes from a remote repository instance to a local one. The pull operation is used for synchronization between two repository instances.
Advantages of Git
1 . Git is Open source license. It is available freely over the internet. As it is an open source, you can download its source code and also
perform changes according to your requirements.
2 . Git does not rely on the central server; that is why, there is no need to
interact with the remote server for every operation performed. Git mirrors entire repository, the size of the data on the client side is small. This illustrates the efficiency of Git at compressing and storing data on the client side.
3. The chances of losing data are very rare when there are multiple copies of it. Data present on any client side mirrors the repository, hence it can be used in the event of a crash or disk corruption.









