Devops(Day -10) Advance Git & GitHub for DevOps Engineers.

Git Branching:

Use a branch to isolate development work without affecting other branches in the repository. Each repository has one default branch and can have multiple other branches. You can merge a branch into another branch using a pull request.

Branches allow you to develop features, fix bugs, or safely experiment with new ideas in a contained area of your repository.

Git Revert and Reset:

Two commonly used tools that git users will encounter are git reset and git revert. The benefit of both of these commands is that you can use them to remove or edit changes you’ve made in the code in previous commits.

Git Rebase and Merge:

What Is Git Rebase?

Git rebase is a command that lets users integrate changes from one branch to another, and the logs are modified once the action is complete. Git rebase was developed to overcome merging’s shortcomings, specifically regarding logs.

What Is Git Merge?

Git merge is a command that allows developers to merge Git branches while the logs of commits on branches remain intact.

The merge wording can be confusing because we have two methods of merging branches, and one of those ways is called “merge,” even though both procedures do essentially the same thing.

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 the dev branch ( Make sure your commit message will reflect as "Added new feature"). [Hint use your knowledge of creating branches and Git commit command]

Add a new commit in dev branch after adding the below-mentioned content in Devops/Git/version01.txt: While writing the file make sure you write these lines

  • 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

In this Process just edit the file, add it and commit every time with a new comment and can verify with Git log --oneline:

Learn GIT Commit command to save New, Modified, or All changed files ...

git log --oneline

Task 2:

Demonstrate the concept of branches with 2 or more branches with a screenshot.

Add some changes to dev branch and merge that branch in master

As a practice try git rebase too and see what difference you get.

Here at First, I create two new branches named Dev-1 & Dev-2 and switch it to Dev-2:

As you can see, I switch to the main branch and we can see there is no file name Version01.txt because we create it in Dev-Branch, now switch it to Dev-Branch and add some content to the file and try to merge it with the master.

Now try to merge it into Master Branch and verify it with ll command to see the Version01.txt file.

Now verify it with the command 'ls' to see the same content of Dev-Branch in the master branch:

You can see we have the same file Version01.txt present in our main branch.

Git Rebase:

Git Visual Reference

Here is What I have done, create a new branch named branch1 from our branch Sub and create a file filex, then add it and commit otherwise it will reflect in all sub-branch and master too then switch into sub-branch and try to rebase it using the command.

Thank you for reading my article.

Have a nice day.