Advance Git & GitHub for DevOps Engineers.

Advance Git & GitHub for DevOps Engineers.

Git Branching

Utilize branches to segregate your development tasks, ensuring they don't impact the integrity of other branches within the repository. Each repository typically includes a default branch and can host numerous additional branches. You can integrate the changes made in one branch into another using a pull request.

Branches provide a controlled space within your repository where you can develop features, address issues, or explore new concepts without jeopardizing the stability of the main codebase.

Git Revert and Reset

Both commands offer the advantage of enabling you to eliminate or modify changes that have been committed to the code in earlier commits.

Git Rebase and Merge

The Git "rebase" command is a tool that allows users to blend changes from one branch into another, resulting in modified commit logs upon completion. Git rebase was created to address the limitations associated with the merging process, particularly regarding commit history

Git merge is a command that enables developers to combine Git branches while preserving the commit history of the individual branches.

The terminology around merging can be perplexing, as there are two distinct methods for merging branches, and one of them is named 'merge,' even though both methods accomplish a similar objective.

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], 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]

  • vversion01.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 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]

  • -Git log is a utility tool to review and read a history of everything that happens to a repository.

  • 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]

  • git reset : Reset current HEAD to the specified state.

  • syntax : git reset <commit_ID> In below image, if you will do git log you can see only two commits as the reset ones are deleted.

  • Now we can see changes in the log file as well.

  • Task 2:

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

      -Creating multiple branch

    • -Switching branch

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

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

- switch to Main branch

- git merge <branch_name> *here branch_name is dev

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

      Git rebase:

      -Rebasing is the process of moving or combining a sequence of commits to a new base commit. Rebasing is most useful and easily visualized in the context of a feature branching workflow. The primary reason for rebasing is to maintain a linear project history.

      Syntax : git rebase <base>

        1. create a new branch

          1. create new file in that branch

          2. add and commit new file to that branch

          3. use command git rebase <branch_name>

Thanks,

Kishor Chavan