🌼Day 11: Master Git & GitHub for DevOps Engineers (Part II)

🌼Day 11: Master Git & GitHub for DevOps Engineers (Part II)

📦 What is Git Stash?

Source: https://www.scaler.com

git stash is a powerful command that temporarily saves the current changes in some hidden area without committing them.

It’s useful when you’re working on a feature branch and need to switch to another branch (e.g., for urgent bug fixes) without committing half-done changes. Here’s how it works:

  1. You make some changes in your working directory.

  2. Instead of committing them, you run git stash.

  3. Git saves your changes in a “stash” (a hidden area), and your working directory becomes clean (matches the latest commit).

  4. Later, when you switch back to your original branch, you can use git stash pop or git stash apply to retrieve your saved changes and continue working on them.

🍒 What is Cherry-pick?

Source: https://geeksforgeeks.org

git cherry-pick allows you to apply the changes introduced by an existing commit to your current branch. It’s useful when you want to selectively pick specific commits from one branch and apply them elsewhere.

⚔️ What is Git Merging Conflict?

Source: https://www.datacamp.com

A Git merge conflict occurs when two or more branches have conflicting changes to the same file. To resolve the merging conflict, you'll need to manually edit the file to incorporate the changes from both branches.

📝Task-01:

  1. Create a new branch and make some changes to it.

     # Syntax
     git checkout -b <branch_name>
     # Example
     git checkout -b stage
    
  2. Use git stash to save the changes without committing them.

     git stash
    
  3. Switch to a different branch, make some changes, and commit them.

     # Syntax
     git switch <branch_name>
     # Example
     git switch main
    
  4. Use git stash pop to bring the changes back and apply them on top of the new commits.

     git stash pop
    

📝Task-02:

  1. In version01.txt of development branch add below lines after “This is the bug fix in development branch” that you added in Day10 and reverted to this commit.

  2. Line2>> After bug fixing, this is the new feature with minor alteration

    Commit this with the message “ Added feature2.1 in development branch”.

  3. Line3>> This is the advancement of previous feature

    Commit this with the message “ Added feature2.2 in development branch”.

  4. Line4>> Feature 2 is completed and ready for release

    Commit this with the message “ Feature2 completed”

  5. All these commits messages should be reflected in Production branch too which will come out from the Main branch (Hint: try rebase).

    Before Rebase:

    After Rebase:

    📝Task-03:

    1. Line to be added after Line3>> This is the advancement of previous feature

    2. Line4>>Added few more changes to make it more optimized.

    3. Commit: "Optimized the feature"

    4. In Production branch Cherry pick Commit “Added feature2.2 in development branch” and added below lines in it:

Happy Coding :) 🙌⚡

Feel free to reach out if you have any questions. I'm delighted to help! 😊

🤝 Let's Connect..!

🔗 LinkedIn

🔗 Twitter

🔗 GitHub

☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️