Git for Beginners: Basics and Essential Commands
- Why Git?
So the main question is : Why we use Git? Before Git, Software Development was already happening. Then what is the problem that we have to use Git.
A case study:
Suppose you are working on a project and you need somebody's help on that project. In that case , you will zip your code, put files in a pendrive and will give it to person 2. Then, person 2 will make some changes and then return back it to you. But how do you know that what changes did Person 2 made ? This is the 1st problem -> We could not track the code.
Suppose, if Person 2 made a mistake in that code and suddenly realized it. Suppose he has a copy of that code. He made changes in his code - But those changes will not visible to me. So 2nd problem is -> Collaboration is not possible.
So to solve this problem, here comes the concept of Git.
- What is Git?
Git is just like a tracker which tracks the changes made in the changes. In technical words, it is the actual Version Controlling System (VCS) which tracks the code. It was developed by Linus Torvalds. Git is installed on the Github. Github is a server used to host Git. We can also independently use Git for local use. There are many other VCS like Mercurial, Apache Subversion etc.
- Git Basics and important terminologies
a) VCS (Version Controlling System): VCS is just like a tracker which tracks the changes made in the code. Git is an example of VCS. The another examples of VCS are distributed systems like Git, Mercurial, and Bazaar, as well as centralized systems such as Subversion (SVN), Perforce P4, and Azure DevOps Server (TFS).
b) VCS Remote (Aso called Remote): VCS Remote is a server which hosts the VCS. Examples include Github, GitTea, BitBucket, AWS Code Commit.
c) Branching : Branching in Git means creating a separate line of development so you can work on new features without affecting the main project.
d) Commit: It refers to the saving of changes in the code to the Git Repository.
e) Staging Area: This is the area in which changes made in the files are prepared before committing them to the Git repository.
f) Hash: Whenever we commit, a Hash of each commit is generated. Each hash has reference to its previous Hash, also called Parent Hash.
g) Head: It refers to the pointer that points to the latest commit in the current branch that user is working on.
h) Git repository: It refers to the directory in which Git saves the project files, commits and history of changes.
- Common Git Commands
These commands are entered in the Terminal section in the code editor that you are using:
i) git init -> This command is used to store changes file. In simple words, it is used to activate Git on a file that starts track/store the changes made in the file.
git add file_name -> This command is used to enable the tracking of the changes made in the file.
git log -> This command is used to show the Git folder History.
git commit -> This command is used to save the changes.
git commit -m"MESSAGE" -> It is same as 'git commit'. But in this command, we can share the additional message .
git status -> It gives the status of the file whether it has been modified or not.
git diff -> This command is used to show the changes made in the file.
git log --one line -> This command is an extension and revised version of 'git log' which gives the entire history in one line.
git revert -> This command is used to revert all the changes made in the file.
git reset -> This command is used to revert all the changes and move all changes to the staging area.
git reset --hard -> This command removes all the changes. This command should not be used very frequently because we can't see the changes made in the file.
git branch -> This command gives the name of current branch.
cat file_name -> It prints all the contents of the file.
cd.. -> It is a Linux command that helps in moving from current folder to yhe previous folder.
ls -> It displays all the contents of a directory. (ls shorts for lists)
git add. -> It is used to add all the files in the tracking position. It is basically an improved version of 'git add file_name' which adds only one file at a time.
Conclusion:
Git is an important tool for developers because it helps in tracking changes, managing projects, and collaborating with other developers. Understanding Git is an essential skill for every developer.
Outro:
In this blog, we learned about Git, why it is used, basic Git terminologies, and common Git commands. I hope this blog helped you understand the basics of Git. After learning these basics, the next step is to practice Git commands and start using GitHub to manage your projects.

