Table of contents
PermalinkHow are Commits stored?
Commits are stored in a data structure called a "commit-graph" in a version control system like Git. Okay, let me show it to you...
Here we can see that each commit refers to its parent commit, forming a chain-like structure.
PermalinkWhy Branching exists?
Branching in version control systems like Git allows developers to work on multiple versions of a project simultaneously without interfering with each other.
This means that one developer can work on a new feature while another developer can work on fixing a bug, and they can both do so in separate branches.
This allows for parallel development and makes it easy to merge the changes back into the main branch of the project when they are ready.
Think of branches as alternative timelines for a project, where each branch is independent of other branches.
If we make changes on one branch, they do not impact the other branches unless we merge the changes.
PermalinkSome facts about Master Branch
The master branch is simply the default branch created along with the repository.
It has no special features or power over the other branches.
In most real-world projects, this branch is treated as the "Official Branch". This means that all the experimental changes are done in other branches and after confirmation, they are merged into the master branch.
In GitHub, the default branch is named "Main Branch". Renamed from Master to Main
PermalinkWhat is a HEAD pointer?
You might get doubt that "How can git manage so many branches?".
The answer is a HEAD pointer. This pointer refers to the latest commit of the current branch. HEAD is analogous to a bookmark card for a book.
So when you switch a branch, the HEAD points to the latest commit, so that you can continue working on your branch, from where you left off.
PermalinkHands-on !!
Permalinkgit branch
This command is used to show all the branches (including sub-branches if any). The asterisk represents the current branch you are in.
Permalinkgit branch -d <branch-name>
This command is used to delete a branch. Note that this command will only work if you are NOT in the branch to be deleted. Use the "-D" option, if it gives a warning.
Permalinkgit branch -m <new-branch-name>
This command is used to rename a branch. Note that this command will only work if you are in the branch to be renamed.
Permalinkgit branch <branch-name>
This command is used to create a new branch, which roots from the current branch you are in. Note that this command does not switch the current branch.
Permalinkgit switch <branch-name>
This command is used to switch branches. Using the option "-c", you can create and switch branches at the same time.
Permalinkgit checkout <branch-name>
This command is also used to switch branches. But this command has many more functionalities. To have a standalone command only for switching, a git switch was introduced.
PermalinkUpcoming Posts:
Merging Branches and Git Diff
All about Stashing
Rehashing
Git Behind the Scenes
PermalinkThank You <3
Damn, you've reached this point 🥳👏. This shows that you are a keen learner🔥. Now do not stop here. There is much more to learn in Git.
Writing blogs is not as simple as we think 🥲. It requires planning, resources, understanding and most importantly TIME🧑💻. I would be very much grateful if you could just share this blog post with your fellow peers (Linkedin, Facebook, Whatsapp, etc). Thank You ❤️
PermalinkOther valuable posts
https://h4rsha.hashnode.dev/git-commit-in-detail
https://h4rsha.hashnode.dev/git-101-shell-commands-mastery
https://h4rsha.hashnode.dev/all-the-basics-you-need-to-start-working-with-git