Chapter 1: Getting Started with Git
A Comprehensive Guide to Git Commands

Software Engineer
What is Git and Why do we need git?
Git represents Global Information tracker
Git is basically a developer’s tool, in technical terms, Git is a free and open source Distributed version control system(VCS), and we can call it as Source code management(SCM) tool.
Git was intoduced in year 2005.
it will maintain multiple versions of same file.
in simple way, Git tracks of every changes you made, so you have record of what has been done, and you can revert back to any specific version. it makes collaboration easy and allow changes done by multiple people and mege it into single source in final.
But what does Version Control System do in practically?
In every application, there are multiple versions of code. For example, when an application is first created, it is called Version 1. As the application grows and new features are added, it is deployed with newer versions of the code, such as v2, v3, and so on.
However, if after deploying a new version to production a feature breaks or the entire application crashes due to faulty code, this is where a Version Control System (VCS) becomes useful. Using a VCS, we can safely roll back from v4 to v3 or any version, the previous stable version in which the application worked correctly.
In simple terms, a version control system allows us to revert to any earlier version of the code without any worry.
But what does tracking in git means?
Tracking a file means it will record complete information about who created that file, when the last changes were made, when exactly it was modified, and what changes were made.
so to keep track of those changes in file, we need tool called GIT.
Git Stages:

entire git depends upon these 3 stages:
Working directory
staging area
repository
Working Directory:
whatever the files created initially in any new project, it will comes under working directory, these files in working directory are not going to track by git,
staging area:
When we run
git add ., the files are moved from the working directory to the staging area. In simple terms, the staging area is where developers make changes that is either data deletion, add or modify. Once changes are committed, they move from the staging area to the repository.repository:
If we make changes to the same file again after committing, it will move from the repository back to the staging area.
why do we need to commit?
To keep track of the history of changes, that is “who made those changes”, “when they were made those changes”, and “what changes they have done”, we need to commit every time when the changes are made.
To install git package in linux, the command is: yum install git -y
To check version of installed git package, the command is: git -v or git - -version or rpm -qa git
initializing git in working directory:
.git: .git means a hidden folder, which is used to keep track of every changes we made, then it will record the history of the changes we made, once we commit it.
git init: to initialize the git in our working directory, we need to add git init to keep track all the files in our project.
git add filename: To keep track of changes we made in any file, we need to do git add filename, then it will be moved from the working directory to the staging area. Now we can commit those changes, and it will keep a history of the changes we have done.
git add * to keep track of all files and folders
git add . To keep track of all files, folders, and hidden files and folders
git commit -m “commit message” filename: To save the history of changes we've made, we need to commit those changes.
git log: To view the history of changes that have been committed.
git show commitId: To see the exact changes made in a specific commit and get complete information about who made those changes, why they made them, and when they did so, use git show commitId.
git config user.name “name”: to set the user name in git. (note: The new name will only appear after a new commit has been made. It won't show for previous commits.)
git config user.email “email”: to set the user email in git. (note: The new email will only appear after a new commit has been made. It won't show for previous commits.)
How to unstage or untrack a file after using the git add command?
git restore —staged filename or git rm —cached filename or git reset or git reset HEAD . To reset the changes that were added to the staging area, use this command.




