Skip to main content

Command Palette

Search for a command to run...

Day 10: Advance Git & GitHub (Part-1)

DevOps Learning

Updated
2 min readView as Markdown
Day 10: Advance Git & GitHub (Part-1)

Git Branching:

  • Branches: Isolate development work without affecting other branches.

  • Default Branch: Each repository has one default branch (often named “master” or “main”).

  • Multiple Branches: Repositories can have multiple other branches (e.g., feature branches).

  • Merging: You can merge a branch into another using pull requests.

Git Revert and Reset:

  • git reset: Removes or edits changes made in previous commits.

  • git revert: Allows you to undo specific commits while preserving history.

Git Rebase and Merge:

  • Git Rebase:

    • Integrates changes from one branch to another.

    • Modifies commit logs.

    • Overcomes merging limitations.

  • Git Merge:

    • Merges branches while keeping commit logs intact.

    • Confusingly, both methods are called “merge.”

Let's practice these essential Git concepts.

Task 1: Branching and Reverting

Objective: Create a new branch, make changes, and then revert those changes using Git.

  1. Create a New Branch:

    • Create a branch named “feature-branch” from the existing “main” branch.

    • Use the following command:

        git checkout -b feature-branch
      
  2. Add a File:

    • Inside the newly created branch, add a text file named feature.txt.

    • Write some content in the file (e.g., “This is a new feature!”).

    • Commit your changes with an appropriate message (e.g., “Added feature to feature-branch”).

  3. Oops! A Bug Crept In:

    • Realize that there’s a bug in your feature. The content should have been “This is a fantastic feature!” instead.

    • Panic mode: Activate!

  4. Revert the Change:

    • Use either git revert or git reset to undo the last commit (the incorrect content).

    • Make sure the content in feature.txt is now “This is a fantastic feature!”

  5. Push Your Branch:

    • Push your local branch to the remote repository (e.g., GitHub).

Task 2: Rebase and Merge

Objective: Demonstrate Git rebase and merging between branches.

  1. Create Two Feature Branches:

    • Create two branches: “feature1” and “feature2.”

    • In each branch, add a file (e.g., feature1.txt and feature2.txt) with some content.

    • Commit your changes in both branches.

  2. Merge Feature1 into main:

    • Switch back to the “main” branch.

    • Merge the changes from “feature1” into “main”:

        git merge feature1
      
  3. Rebase Feature2 onto main:

    • Still in the “main” branch, rebase “feature2” onto it:

        git checkout feature2
        git rebase main
      
  4. Observe the Differences:

    • Compare the commit history and logs after merging and rebasing.

Thank you for reading😉.