Table of contents
Git Branching :
Git branching is a way to create different versions of a project within a Git repository. Think of it as a tree where the main trunk represents the master branch of your project, and each branch is a separate path or version that can be worked on independently.
When you create a branch, you're essentially creating a copy of the current state of your code. You can make changes to this copy without affecting the original master branch. Once you're done with the changes, you can merge the branch back into the master branch to combine the changes you made.
Branching is useful when you want to work on a new feature or fix a bug without disrupting the main codebase. It allows multiple people to work on different parts of the project simultaneously without interfering with each other. You can also use branches to experiment with new ideas, test new features, or work on different versions of your code.
Git Revert and Reset :
Git revert and reset are two ways to undo changes in a Git repository, but they work in slightly different ways.
Git revert is used to undo a specific commit by creating a new commit that undoes the changes made in the original commit. Think of it as going back in time and erasing the changes that were made, without actually deleting the commit itself. This is useful when you want to keep a record of the original commit, but you need to undo the changes it made.
For example, if you realize that a recent commit introduced a bug in your code, you can use git revert to undo that commit and fix the bug. This creates a new commit that undoes the changes made in the original commit but keeps a record of both commits in your repository.
Git reset, on the other hand, is used to undo changes by resetting the repository to a specific commit or state. This means that any changes made after that point will be lost. It's like rewinding the repository to an earlier state and starting over from there.
For example, if you made several commits that you no longer need and you want to start over from a previous commit, you can use git reset to reset the repository to that commit. This deletes all the commits made after that point, so be careful when using this command.
Git Rebase and Merge :
Git rebase and merge are two ways to integrate changes from one branch into another, but they work in different ways.
Git merge combines changes from two branches into a new commit on the destination branch. Think of it as taking two branches of a tree and merging them together to create a new branch. This creates a new commit on the destination branch that includes all the changes made in both branches.
For example, if you have a feature branch with some changes that you want to add to the main branch, you can use git merge to merge those changes into the main branch. This creates a new commit on the main branch that includes all the changes made in the feature branch.
Git rebases, on the other hand, rewrites the history of the destination branch to include changes from the source branch. Think of it as taking the source branch and placing it on top of the destination branch, as if it was there all along. This creates a linear history in which the changes from the source branch appear before the changes from the destination branch.
For example, if you have a feature branch with some changes that you want to add to the main branch, you can use git rebase to apply those changes on top of the main branch. This rewrites the history of the main branch to include the changes from the feature branch as if they were made directly on the main branch.
FOLLOW ME for more blogs.
Thanks.