Day 11 Task: Advance Git & GitHub for DevOps Engineers.

Day 11 Task: Advance Git & GitHub for DevOps Engineers.

ยท

8 min read

โœฅWhat Is Git Branching?

๐ŸŒณ Git Branching:

  1. Master Branch (Main Trunk): ๐ŸŒณ This is the default and main part of your project. It's the stable version where your working code resides.

  2. Creating a Branch: ๐ŸŒฑ When you want to try out a new feature or fix a bug without affecting the main trunk, you create a branch. It's like growing a new branch on the tree.

  3. Switching Branches: ๐Ÿ”„ You can switch between branches, moving from one path to another. It's like jumping between different directions your project could take.

  4. Making Changes in a Branch: โœ๏ธ In your branch, you can make changes to your code. It's like adding leaves or modifying parts of that specific branch without affecting the main trunk.

  5. Merging Branches: ๐Ÿ”€ Once your new feature or bug fix is ready and tested, you can merge that branch back into the main trunk. It's like combining different branches back into the main tree.

  6. Deleting Branches: ๐Ÿ—‘๏ธ After merging, you can delete the branch if you don't need it anymore. It's like pruning a branch that served its purpose๐Ÿช“.

  7. Conflict: ๐Ÿคฏ Sometimes, if someone else changed the main branch while you were working on your branch, there might be a conflict.

    You need to resolve conflicts, ensuring everything fits together smoothly๐Ÿ”ง.

Git branching allows you to explore new ideas or work on different features, make changes, and merge them back into the main project tree without disturbing the stability of the existing code.

โœฅWhat Is Git Revert?

๐Ÿ”„ Git Revert:

  1. Oops! Made a Mistake ๐Ÿ™ˆ:

    • Imagine you made a change (a commit) that didn't turn out well. ๐Ÿคฆโ€โ™‚๏ธ
  2. Enter Git Revert ๐ŸŽญ:

    • Git Revert is like a magician's wand to undo a commit's changes. ๐Ÿช„
  3. Creating a Revert Commit ๐Ÿ“œ:

    • When you revert a commit, Git doesn't erase history. Instead, it creates a new commit that undoes the changes. ๐Ÿ“
  4. Back to Before ๐Ÿ•ฐ๏ธ:

    • Your project is now back to the way it was before the "oops" commit. โฎ๏ธ
  5. Multiple Reverts ๐Ÿ”„:

    • You can revert multiple commits if needed, each creating a new commit to undo its changes. ๐Ÿ”„
  6. Careful with Shared Commits ๐Ÿšจ:

    • If others have pulled your changes, be cautious. Reverting shared commits can create confusion. ๐Ÿค”
  7. Commit History ๐Ÿ“š:

    • Git Revert helps maintain a clean and transparent commit history. ๐Ÿ“Š

Git Revert is like a safety net. When you've made a mistake, it allows you to go back in time and undo changes without erasing the past. ๐ŸŽฉ๐Ÿ”ฎ

โœฅWhat Is Git Reset?

๐Ÿ”™ Git Reset:

While working on a project each commit is like a snapshot of your project at a specific moment. โฐ๐Ÿ“ธ

  1. Making a Jump in Time โฉ:

    • Sometimes, you want to go back to a previous point in your project's history. It's like time-travelling to an earlier snapshot. โช๐Ÿ•ฐ๏ธ
  2. Types of Reset ๐Ÿ”„:

    Soft Reset ๐Ÿงธ: (Keeping Changes)

    • A soft reset is like going back in time without changing much. It keeps your changes but moves you to a different snapshot. ๐Ÿ”„๐Ÿž๏ธ

Hard Reset ๐Ÿš€: (Discarding Changes)

  • A hard reset is more powerful; it's like going back and starting over from a specific snapshot. Your changes are gone, and you're back in time. ๐Ÿ”„๐Ÿšซ๐Ÿ“ธ

Mixed Reset ๐ŸŽญ(default): (Unstaging Changes)

  • A mixed reset is in between. It's like going back, keeping your changes, but uncommitting them. You're still at an earlier point in time. ๐Ÿ”„๐Ÿ”ง
  1. Undoing Commits ๐Ÿ“๐Ÿ”„:

    • Git reset is often used to undo commits. It's like erasing part of your project's history and going back to an earlier state. ๐Ÿ“๐Ÿ”„๐Ÿ—‘๏ธ
  2. Use with Caution โš ๏ธ:

    • Be careful with resets, especially hard resets, as they can discard changes permanently. It's like handling a powerful time-travel device. โš ๏ธ๐Ÿšจ๐Ÿคž

So, Git Reset is your time-travel tool in the project universe, allowing you to go back to different moments in time, either keeping or discarding changes as needed. โฐ๐Ÿ”„๐ŸŒŒ

โœฅWhat Is Git Rebase?

โณGit Rebase:

  1. Branching off for a New Feature ๐ŸŒฑ:

    • You start a new branch to work on a feature. ๐Ÿ“๐ŸŒฒ
  2. Others Are Writing Too ๐Ÿค:

    • While you were working on your branch, others made changes in the master branch. ๐Ÿ“š๐Ÿ‘ฅ
  3. Fetch Updates ๐ŸŽฃ:

    • Time to sync up! So you fetch the latest changes from the master branch. It's like catching up on what others have written. ๐Ÿ”„๐Ÿ‘€
  4. Rebasing Your Changes ๐Ÿ”„:

    • Instead of merging, you rebase your branch on top of the latest master branch changes. ๐Ÿ”„๐Ÿ“
  5. A Linear, Clean Path ๐Ÿ›ค๏ธ:

    • Rebasing creates a cleaner, linear history without extra merge commits. After the rebase, there's a straight, clean timeline without the messy divergences. ๐ŸŒŸ๐Ÿ”„
  6. Potential Conflicts ๐Ÿค”:

    • There might be conflicts during the rebase, but you resolve them just like editing overlapping parts in your chapter. ๐Ÿ”ง๐Ÿ’ฌ
  7. Pushing the Updated Chapter ๐Ÿš€:

    • After a successful rebase, you push your updated code. It's like sharing your revised work with others. ๐Ÿš€๐Ÿ“ค
  8. Collaborative Coding ๐Ÿค:

    • Rebase keeps the code linear, making it easier for everyone to follow. It's like ensuring a cohesive, collaborative coding experience. ๐Ÿ“š๐Ÿ‘ฅ
  9. Considerations for Shared Branches โš ๏ธ:

    • Be cautious when rebasing shared branches, as it rewrites history. It's like editing a shared code; everyone needs to be on the same page. ๐Ÿ‘ฅ

Git Rebase is like editing your code to smoothly integrate with the latest developments in the main branch, creating a cleaner, more cohesive narrative. ๐Ÿ”„๐Ÿ“–

โœฅWhat Is Git Merge?

๐Ÿ”€ Git Merge

Git Merge is like a team meeting ๐Ÿค where different contributors ๐Ÿง‘โ€๐Ÿ’ป bring their work together into a unified project. It creates a new commit ๐Ÿ”„, blending individual efforts into a cohesive code ๐Ÿ“– while keeping everyone's contributions intact. ๐Ÿš€๐Ÿ‘ฅ

โœฅ๐Ÿ”„ Git Rebase vs Merge:

Git Rebase:

  • ๐ŸŽฌ Visual Flow:

    • Creates a linear, clean code by moving your changes on top of another branch.
  • ๐ŸŽจ Interactive:

    • Allows you to rearrange, edit, or squash commits for a tidier history.
  • ๐Ÿงผ Cleaner History:

    • Helps in reducing redundancy and maintaining a more straightforward timeline.

Git Merge:

  • ๐Ÿค Team Meeting:

    • Combines different branches in a collective team meeting.
  • ๐Ÿ”„ New Commit:

    • Generates a new commit, capturing the merge decision and blending contributions.
  • ๐Ÿ“– Preserves History:

    • Maintains the original branching structure and each contributor's work.

Git Rebase provides a cleaner, more linear history with interactive features, while Git Merge preserves the collaborative nature and original structure of contributions. ๐Ÿ”„๐Ÿค

โœฅWhat Is Git Stash?

Git Stash ๐Ÿ“ฆ:

Imagine you're working on a project, making changes to your code. Suddenly, your boss or a colleague asks you to quickly fix a bug or address an urgent task. You're in the middle of something, and you don't want to commit your unfinished changes.

This is where Git Stash comes to the rescue!

  1. Stashing Changes ๐Ÿ“ฆ:

    • When you stash changes, it's like putting your messy desk into a neat box. You stash away your unfinished work, so your desk (code) looks clean for the urgent task.
  2. Stash List ๐Ÿ“‹:

    • Stashes are like hidden boxes under your desk. You can have multiple stashes for different tasks, and Git keeps track of them.
  3. Apply Stash ๐Ÿ“ค:

    • Once you're done with the urgent task, you can bring back your original messy desk (code) by applying the stash. It's like taking the box from under the desk and unpacking it.
  4. Pop Stash ๐Ÿ”„:

    • Pop is like applying the stash and also throwing away the box. It's a quick way to get back to your previous state.

Git Stash is your secret storage for unfinished work. It lets you clean up your workspace temporarily, deal with urgent tasks, and then come back to your work without messing up your changes! ๐Ÿš€

โœฅWhat Is Cherry-pick?

Git Cherry-pick ๐Ÿ’๐Ÿ”—:

Imagine you have a basket of cherries (commits), and you want to pick just one cherry and add it to another basket (branch). Git Cherry-pick helps you do just that!

  1. Pick a Cherry ๐Ÿ’:

    • You have a tree with many branches (commits on different branches), and you want one specific commit from another branch. Cherry-pick allows you to pluck that particular commit like picking a cherry from a tree.
  2. Add to Your Basket ๐Ÿงบ:

    • Once you've picked the cherry (commit), you add it to your basket (current branch). This means you're taking changes from one specific commit and applying them to your current working branch.
  3. No Need for the Whole Tree ๐ŸŒณ:

    • Cherry-pick lets you be selective. You don't need to pick the entire tree (branch) with all its cherries (commits). You can choose and add only the ones you want.
  4. Cherry-pick Conflicts ๐Ÿคนโ€โ™‚๏ธ:

    • Sometimes, if the cherry you're picking has changes that conflict with your current basket (branch), you might need to resolve those conflicts. It's like juggling to make sure everything fits nicely.

Git Cherry-pick is like selectively picking cherries (commits) from one branch and adding them to another branch. It helps you keep your version control deliciously organized! ๐Ÿ’๐Ÿ”—โœจ

"๐Ÿ™Œ Thank you for taking the time to explore this blog!๐Ÿ“š I hope you found the information both helpful and insightful.โœจ

๐Ÿš€ Enjoy your learning journey, and don't hesitate to reach out if you have any feedback. ๐Ÿค“ Happy exploring!"

ย