Day10/90DaysofDevOps challenge -Advance Git & GitHub for DevOps Engineers

Day10/90DaysofDevOps challenge -Advance Git & GitHub for DevOps Engineers

GIT Branching:

Branching in Git allows us to work on different features, bug fixes, or experiments in isolation, without affecting other parts of the repository. Each repository has a default branch, usually called "master" or "main," and we can create multiple other branches to work on specific tasks.

Git branching enhances productivity by ensuring proper coordination among developers and helping organize a series of planned, structured releases. Having a branching is necessary to avoid conflicts when merging and to allow for the easier integration of changes into the master.

Git revert and reset

git reset and git revert are commands that you can use to remove or edit changes you’ve made in the code in previous commits. Understanding how both of them work will save you a significant amount of time, allow you to make cleaner code, and have more confidence in making commits when you do.

Git revert:

  • git revert is used to create a new commit that undoes the changes made in a previous commit.

  • It is a safe way to undo changes since it does not modify the commit history. Instead, it adds new commits that reverse the changes made by a specific commit.

  • When you run git revert <commit>, Git will create a new commit that undoes the changes introduced by the specified commit.

  • This command is useful when you want to undo changes while preserving the commit history and keeping a record of the reverted changes.

    Git reset:

    • git reset is used to move the current branch pointer to a different commit or to modify the staging area and working directory.

    • It allows you to reset the state of the repository to a previous commit, discarding commits and potentially losing changes

    • git reset --hard <commit> moves the branch pointer to the specified commit and discards all changes made after the specified commit. It resets both the staging area and the working directory.

      Git Rebase and Merge:

      git rebase:

      • git rebase is used to incorporate changes from one branch onto another by moving or replaying commits.

      • It allows you to apply the commits of one branch on top of another branch, resulting in a linear commit history.

      • When you run git rebase <branch>, Git identifies the common ancestor commit between the current branch and the specified branch. It then applies each commit from the current branch onto the specified branch, one by one.

git merge:

  • git merge is used to combine changes from one branch into another by creating a new merge commit.

  • It integrates the changes from a source branch into a target branch, preserving the commit history of both branches.

  • When you run git merge <branch>, Git creates a new commit that represents the combination of changes from the specified branch into the current branch.

Task1:

Add a text file called version01.txt inside the DevOps/Git/ with “This is the first feature of our application” written inside

  • Create a text file called version01.txt inside the DevOps/Git/directory and Write the content "This is the first feature of our application" in the file.

  • Create a new branch named dev from the master branch git checkout -b dev

  • Commit your changes with the message "Added new feature."

    git add version01.txt

    git commit -m "Added new feature"

    Push to Remote:

    • Push the dev branch to the remote repository for review.

      git push -u origin dev

Task 2:

Continuing from Task 1, let's move on to the next set of actions:

  • Step 3 - Add More Content:

    • Switch to the dev branch.

    • Edit version01.txt and add the following lines:

        1st line>> This is the bug fix in the development branch
        Commit this with the message "Added feature2 in the 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
      

Task 3

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

Add some changes to the dev branch and merge that branch into the master

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

If you find my blog valuable, I invite you to like and share. Your feedback is precious as it fuels continuous improvement. Let's embark on this transformative DevOps adventure together!🚀🚀

Thank you😊!!