πŸ’¦Day 10: Master Git & GitHub for DevOps Engineers (Part I)

Β·

3 min read

πŸ’¦Day 10: Master Git & GitHub for DevOps Engineers (Part I)

🎯 What is Branching in DevOps?

  • The branching is a separate line of development from the main code, which allows developers to track and make changes to their code over time without affecting the main line of code.

How to Use Git Branches & Buddy to Organize Project Code β€” SitePoint

Source: https://www.sitepoint.com

🎯 What is Git Revert & Git Reset?

Source: https://ln.ki/KodeKloud-IG

  • Git Revert: Git Revert generates a new commit that undoes the changes made in a previous commit.

  • Git Reset: Git Reset discards all commits after a specified commit.

🎯 What is Git Rebase & Git Merge?

Source: https://ln.ki/KodeKloud-IG

  • Git Rebase: Git Rebase updates the current branch with changes from another branch.

  • Git Merge: Git Merging is the process of combining two branches into one.

Exercises:

πŸ“Task 1: Exploring the Revert and Reset concept in Git

🐾Step 1: Add a text file called version01.txt inside Devops/Git/ with "This is first feature of our application" written inside and coming from the Master branch.

🐾Step 2: version01.txt should reflect at the local repo first followed by the remote repo.

🐾Step 3: Add a new commit in dev the branch after adding the mentioned content in Devops/Git/version01.txt: While writing the file make sure you write these lines:

  1. 1st line>> This is the bug fix in development branch

  2. Commit this with the message β€œ Added feature2 in development branch”

  3. 2nd line>> This is gadbad code

  4. Commit this with the message β€œ Added feature3 in development branch

  5. 3rd line>> This feature will gadbad everything from now.

  6. Commit with the message β€œ Added feature4 in development branch

🐾Step 4: Restore the file to a previous version where the content should be β€œThis is the bug fix in development branch”.

# Syntax
git reset --hard <commit_hash>
# Example
git reset --hard 2e5b93b

πŸ“Task 2: Understanding the Concepts of Rebasing and Merging in Git

Git Rebase vs. Merge: A Complete Guide

Source: https://www.simplilearn.com

🐾Step 1:

(Case 1): Merge feat-1.txt and feat-2.txt files from the Stage branch into the Main branch.

# Syntax
git merge <branch_name>
# Example
git merge stage


(Case 2): Merge the feat-4.txt file from the Stage branch into the Main branch.

# Syntax
git merge <branch_name>
# Example
git merge stage

Note: In case 2, when merging from the Stage branch to the Main branch, both HEADs are not aligned on the same line as observed in case 1. Hence, it's not necessary to emphasize being on the same branch.

🐾Step 2: Rebase the Main and Stage branch in the same line.

# Syntax
git rebase <branch_name>
# Example
git rebase main

Note: When you observe a rebase conducted from the staging branch to the main branch, both HEADs synchronize on the same line. Rebase brings the main and staging branches into one history, unlike merge, which doesn't follow this linear synchronization history.

Happy coding! 😊🐾

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

🀝 Let's Connect..!

πŸ”— LinkedIn

πŸ”— Twitter

πŸ”— GitHub

β˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈβ˜€οΈ

Β