DEV Community

Cover image for Understanding Git in Simple way - Part 2
Ganesh Kumar
Ganesh Kumar

Posted on

Understanding Git in Simple way - Part 2

Hello, I'm Ganesh. I'm working on FreeDevTools online, currently building a single platform for all development tools, cheat codes, and TL; DRs — a free, open-source hub where developers can quickly find and use tools without the hassle of searching the internet.

Previously, we understood what Git is and what a Git commit is.
In this blog, we will understand more about git.

Why Git uses DAG?

Git DAG

Each commit holds changes, will have Snapshot, Metadata, and the parent commit id.
Each commit will be pointing to its parent.

Hence, there will be no way it can form a cyclic or forming a loop for commit history.

This will be in a Directed Acyclic Graph (DAG) structure.

The Graph created will have a history of every commit, and every decision that the developer made will be captured in this structure.

This will make Git powerful. As we can jump to any point in a commit.

How Branching Works?

We usually assume the branch has a full copy of parent commit and we try to commi changes on top it. Which is a wrong assumption.

The branch will have a parent ID; that's it. Similar to any other commit.

Let's understand with an example.
Master Branch.

Create New Branch

git checkout -b iss53
Switched to a new branch "iss53"
Enter fullscreen mode Exit fullscreen mode
git branch iss53
git checkout iss53
Enter fullscreen mode Exit fullscreen mode

Commit changes

If you want to change anything in the master branch

Checkout to the branch

git checkout master
Switched to branch 'master'
Enter fullscreen mode Exit fullscreen mode

And commit changes

Conclution

The DAG is your project's history, which has every branch, every merge, and every decision the developers made in the project.

We understood how the branch works. How a branch is created.
In the next blog, we will understand how Git knows where we are working and how branches are merged by PR.

Top comments (0)