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

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

Git Branching

Branching is a feature provided in git so that developers can create code related to different functionalities on separate branches. This helps the developer team to create the code in an uncluttered way. Later this code can be merged with a Master branch which is a default branch in git.

Git Revert and Reset

Git revert and reset are two commands commonly used in Git version control system to remove or edit changes you’ve made in the code in previous commits. However, they have different functionalities.

Git revert undoes the changes made by a previous commit by creating an entirely new commit, all without altering the history of commits. The revert command can be useful in situations where a mistake is made in a commit, and you want to undo the changes made without removing the commit from the history.

Git reset, on the other hand, is used to reset the repository to a specific commit. The reset command removes all the commits after the specified commit from the repository history. This command is useful in situations where you want to undo a series of commits or remove a commit from the repository history.

Git Rebase and Merge

Git rebase and merge are two different ways of combining changes from one branch to another branch in Git.

Git merge is a command used to combine changes from one branch to another. When you merge a branch, Git takes the changes made in the source branch and applies them to the target branch, creating a new merge commit that contains the changes from both branches. The merge commit is then added to the history of the target branch.

Git rebase, on the other hand, does not create a new commit instead takes the changes made in the source branch and applies them on top of the target branch. This creates a linear history without any merge commits, making it easier to follow and understand the changes made to the repository.

Task 1:

Add a text file called version01.txt inside the Devops/Git/ with “This is first feature of our application” written inside. This should be in a branch coming from master, [hint try git checkout -b dev], swithch 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]

  • version01.txt should reflect at local repo first followed by Remote repo for review. [Hint use your knowledge of Git push and git pull commands here]

Add new commit in dev branch after adding 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 development branch

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

  • 2nd line>> This is gadbad code

  • Commit this with message “ Added feature3 in development branch

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

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

Restore the file to a previous version where the content should be “This is the bug fix in development branch” [Hint use git revert or reset according to your knowledge]

Task 2:

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

    From the dev branch, I have added 2 more branches: feat/add1 and feat/add2.

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

  • Create a file.txt file in dev branch and merge it with main (in my case the default branch is main)

  • Status of the main branch before performing git merge.

  • Status of the main branch after performing git merge.

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

  • Create a new branch stage from main branch and make some changes.

  • Checkout to main branch and check the status before rebasing.

  • Status of the main branch after performing git rebase.

  • \>>>>>>>>>>>>>> Thank you for reading! :-)<<<<<<<<<<<<<<<