Day 13 Task: Advanced Git & GitHub for DevOps Engineers

In this task, you’ll explore advanced Git concepts like branching, reverting/resetting commits, and rebasing/merging. These concepts are crucial for collaborative software development and maintaining clean, structured code repositories.


1. Git Branching

Branches are a fundamental part of Git. They allow you to isolate development work from the main codebase. Each repository starts with one default branch (typically "main" or "master") and can have multiple branches for features, bug fixes, or experiments.

  • Why Branching? It’s ideal for working on features or fixing bugs without interfering with other parts of the project.

  • How It Works: Once you create a branch, you can commit changes to that branch. When the feature is ready, you can merge it into the main branch via a pull request.


2. Git Revert and Reset

Both git revert and git reset allow you to undo changes, but they work in different ways:

  • Git Reset: Moves the branch pointer to a previous commit. You can use this when you want to remove commits and rewrite history.

  • Git Revert: Creates a new commit that undoes the changes of a previous commit without altering the commit history. It's safer when you're working with a team.


3. Git Rebase and Merge

  • Git Rebase: This command integrates changes from one branch to another by modifying the commit history. It’s useful for keeping a clean project history by avoiding unnecessary merge commits. However, it rewrites the commit history, so you should be careful when using it with shared branches.

  • Git Merge: Combines changes from one branch into another while preserving the commit history of both branches. It’s great for maintaining the context of changes.


Tasks

Task 1: Feature Development with Branches

  1. Create a Branch and Add a Feature:

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

    Create a new branch from master.

    •   git checkout -b dev
      

Commit your changes with a message reflecting the added feature.

  1. Push Changes to GitHub:

  2. Add More Features with Separate Commits:

    Update version01.txt with the following lines, committing after each change:

    1st line: This is the bug fix in development branch

    2nd line: This is gadbad code

    3rd line: This feature will gadbad everything from now

  3. Restore the File to a Previous Version:

    Task 2: Working with Branches

    1. Demonstrate Branch Structure Create 2 or more branches and take screenshots to visualize the branch structure. You can list branches with:

       git branch
      

      Example:

       git checkout -b feature-1
       git checkout -b feature-2
      

      Take screenshots of these branch structures to document the workflow.

    2. Merge Changes into Master Make some changes to the dev branch and merge them into the master (or main) branch:

       git checkout master
       git merge dev
      
    3. Practice Rebase Rebase the dev branch on top of the master branch:

       git checkout dev
       git rebase master
      

      Observe the difference: Instead of a merge commit, the rebase will place the dev branch's commits on top of the master branch as if they were committed sequentially after the master’s commits.


Conclusion

By diving deeper into Git, you’ve explored critical workflows like branching, merging, reverting, and rebasing. These advanced operations allow you to manage project development with precision, ensuring code quality, collaboration, and a clean commit history.

*

0
Subscribe to my newsletter

Read articles from Amit singh deora directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Amit singh deora
Amit singh deora