In this blog, you will learn about:
Reason to develop Git:
- What is Git?
- Why do we use Git?
- Git’s basics and core terminologies.
- Common git commands
Imagine you and your friend are working on a learning management system. You have divided the project into 2 sections. You are building the authentication system; Ahmed is building the other section. Now the first problem you will face is that you were building that, and you cannot track which person added which code and when, like you were building a user login feature, and then everything was ok, and then you moved to the forgot password code, but when you were writing that code, you unknowingly changed the line in the previous code's functionality, and now you are facing an error, but now you do not know which function has caused the bug, and now you both are confused and blaming each other. Now the only possible way is to debug both functions, which will take your time.
If there would exist a system that can track what, when, and who changed the code, then this problem will be solved easily. Basically you need a system that shows the history of your project.
Why was Git created?
Where there is a problem, there is a solution. In that case , the solution was git. Before Git, there was a system called BitKeeper. Linus Torvalds, who is the founder of Linux and Git, was using BitKeeper. During the development of Linux, they were using BitKeeper, but when its free license expired, he developed Git as a side project. This system was developed to provide efficient versioning
What is Git?
Git is a distributed version control system. The full form of “GIT” is “Global Information Tracker.”
It tracks four things about code
- When did it change?
- What was changed?
- Who made the change?
- Why did it change?
Think of it as a "time machine" for your project. It allows you to save "checkpoints" (called commits) of your work. If you mess something up, you can instantly revert your entire project back to how it looked an hour ago, yesterday, or even last year.
Why do we use Git?
We use Git for the following reasons:
Version Control: It track all the changes that are done in code and who changed the code and when
Collaboration: It allows multiple people to work on the same file at the same time without overwriting each other's work (most of the time).
Distributed: This is the important point. Unlike older systems where code lived on one central server, in Git, every developer has a full copy of the entire project history on their laptop. If the central server explodes, you can restore everything from your coworker's laptop.
Git’s basics and core terminologies
1. Repository
The folder that is being tracked by the git is known as the repository.
Real-life analogy:
Think of it like a personal journal or diary that stores your complete work and how it evolved over time.
2. Staging Area
It is the place where changes are placed before committing. When we run ‘git add .’ or ‘git add ’, it is known as staging the code. The code in staging phase is known as staged code or staged changes
Real-life analogy:
Packing the items in a box for shipping.
3. Commit
It is like the screenshot of the project at the current moment. It remembers all the files, the folder structure, and the extra information, like who made it, when, and why.
As shown in this diagram, every commit has the current code of the project. This diagram is the example of how commit works. Like, you’re working on the authentication system and wrote signup code, and you commit this code, and then you added login code, and then this commit will have login code + signup code (and the changes in it if any were made). And after adding this forgot password code, now this commit will have the forgot password code and changes done in the previous commit.
Common commands Used in Git:
The commonly used git commands are
- git init
- git add and git add .
- git status
- git log
- git commit
- git reset
- git reset --hard
The explanation of these commands is given below:
1. git init
It is like telling the git to track every change in a folder.
Working of Command:
It initializes an empty Git repository inside the folder. That Git repository is basically a hidden .git folder. This is where Git stores everything that needs to track changes, history, and versions of the project.
2. git add and git add .
These two commands are similar to each other to some extent. The main purpose of these commands is like telling Git to stage our current changes. In simple words, it is like telling Git to stage current changes (or, in simple words, save them so they can be included in the next commit).
3. git status
It tells us the current condition of the folder. It provides information about:
- Which files are untracked?
- Track files that are modified or deleted
- Changes that are to be commited
4. git log
It tells us information about commits.
It tells:
- Author (who made the commit)
- Date and time of commit
- Commit ID
- Commit message
- **git commit -m “” It takes a snapshot of all the staged changes and saves them permanently in Git history.
Important point: Git only included staged changes. Like, if you ran the git add . command and staged the changes and then changed any file, now git will not include the changes made after staging.
6.git reset
This command is used to undo the changes that were done after a specific commit. It only moves the changes from the commit phase to the staging phase.
The ID of that commit is mentioned in the command.
It only moves the head from the current commit to that specific commit.
Diagram
Now the commit is on Commit 3, but when you run the reset command. Then the head will move to that commit.
Quick Git Challenge
If you have understood this, tell me in the comments if you had three commits and then staged some changes; after this, you ran this command: git reset . Now will staged changes remain staged, or will they become unstaged? tell me in the comments?
7.git reset --hard
It is the same but a stricter version of the previous reset command because in this, changes are not untracked; they are deleted.
Conclusion:
Now you have learned how Git solved our problem; it has added a hidden .git folder in which it tracks everything about our project.
In my next article, I will write in detail about the structure of the .git folder. So you can understand about how Git works under the hood. Stay tuned!
💡 If you find this article useful, please provide your feedback in the comments. Also if you find any mistake, tell me so i can improve it








Top comments (0)