Day 10 Task: Advance Git & GitHub for DevOps Engineers.

What is Branch?

A Branch is a representation of different isolated versions of code. Let me explain with a help of an example.

I have cloned the repository from GitHub.When you enter the repository the default branch name of your repository is main, as shown in the picture above I am creating a file and made some changes after that I staged the files and committed them in the main branch.

As shown in the image above, I have created a new branch dev by the command git checkout -b dev and added the files into it. In this way, branches are made in git so that developers can isolately work on their code and add new features to it without disturbing the existing code in the main branch.


In the above image, I had committed 3 changes in the dev branch and I want to merge this dev branch into main branch.

So here comes the concept of merging,

What is Merging?

In general, merging means combining something into a single entity.

In Git, merging is a technique that is used to include the changes from one branch to the other branch.

In Git, merging is of two types:- Git Merge and Git Rebase

Git-Rebase
In Git Rebase, logs are modified after merging the two branches. Git rebase was introduced to overcome the limitation of merging, i.e., to make logs of repository history look linear.

This is the git log of the main branch.

This is the git log of the dev branch.

In the above image, I merged the dev branch on main by git rebase dev such that it will integrate the changes from the dev branch into the main branch. As you can see in the git logs, the head is on the main (the head defines the latest state of the commit), and it contains all the changes from the dev branch. It makes the log commits in a linear fashion.

Task 1:- Add a text file called version01.txt inside the Devops/Git/ with “This is the first feature of our application” written inside. This should be in a branch coming from master, [hint try git checkout -b dev], switch to dev branch ( Make sure your commit message will reflect as "Added new feature"). [Hint use your knowledge of creating branches and Git commit command]

  • 1st line>> This is the bug fix in the development branch

  • Commit this with the message “ Added feature2 in development branch”

  • 2nd line>> This is gadbad code

  • Commit this with the message “ Added feature3 in the development branch

  • 3rd line>> This feature will gadbad everything from now.

  • Commit with the message “ Added feature4 in the development branch

Used git revert to undo the changes back to their previous versions, it will create a new commit. We can also do a git reset also but it will not preserve the commit history, which is not a good practice.