Day12 of #90DaysOfDevOps: Advance Git for DevOps Engineers

Hello! It's Day 12 of the #90DaysOfDevOps Challenge, and we've already covered a lot, like what is Git and GitHub. Now, let's dive into some more advanced topics.

Today, we're going to explore some advanced concepts of Git and GitHub.

Here we goo..

What is Git Branching.?

Git Branching means diverging from the mainline and continue to work separately without messing with the mainline. In other words, a branch is a new/separate version of the main repository. Branches allow you to work on different parts of a project without impacting the main branch. When the work is complete, a branch can be merged with the main project. Branching in Git is very lightweight and fast!

To create branch you use the following command

git branch <branch-name>

What is Git Revert and Reset.?

Git Revert is like an undo button, but instead of erasing the past, it creates a new commit that reverses the changes from a previous commit. This way, your history stays intact, and nothing is deleted. It’s a safe option when you want to fix something but still keep a record of everything that happened.

Git Reset is more like hitting the rewind button. It moves the branch pointer to an earlier commit and can completely remove the commits that came after, depending on how you use it. This means those changes are wiped out as if they never happened, which can be risky, especially if you’ve already shared your work with others.

What is Git Rebase and Merge.?

Git Rebase is a way to move or combine a series of commits to a new base commit. It lets you take changes from one branch and apply them on top of another branch.

Git Merge is a way to combine changes from one branch into another. When you merge a branch, Git creates a new commit called a merge commit.

Let’s do some hand’s on…

We’re going to Develop feature with branches and restore the bad commit.

Firstly, we have to create file!

Now creating a Branch called dev

First Commit changes with a message reflecting the file added

now updating the file and commit the change with the message “Added Feature1”

Updating the file with bad code..!

Updating the file..!

Here we committed 3 changes and the second one is corrupt. So we have to revert the second commit “This is bad code”.

git revert commit-Id

This command reverts the last second commit, effectively removing the "This is bad code” lines.

Lets work with Branches

  • Creating 2 or more branches and show the branch structure.

    Merge Changes into feature:

Make some changes to the feature2 branch and merge it into feature.

git merge feature

Managing branches in Git is crucial for maintaining an organized workflow and enabling seamless collaboration. As you delve deeper into branching strategies, keep in mind that effective branch management not only enhances the structure of your codebase but also simplifies the process of integrating changes and resolving conflicts later.

Stay tuned for more insights as I continue my #90DayOfDevOps challenges. If you have any questions or tips, feel free to share them in the comments.

Let’s keep learning and growing together! 🚀