Advance Git & GitHub for DevOps Engineers: Part-2

Advance Git & GitHub for DevOps Engineers: Part-2

Index

Β·

5 min read

Introduction
Git Stash
Cherry-pick
Resolving Conflicts
Task-01
Task-02
Task-03
Conclusion

Introduction

Welcome back to the DevOps journey! 🌐 In this next installment, we're diving into advanced Git techniques:Learn the art of stashing changes without committing. Perfect for quick context switches and keeping your workflow seamless. πŸ’ΌCherry-pick the best features, handle conflicts with finesse, and keep your codebase sleek! 🀝Navigate through Git's conflict markers, harmonize divergent changes, and maintain code integrity like a pro! πŸš€Excited? Buckle up for these three tasks in "Advance Git & GitHub for DevOps Engineers: Part-2"! πŸŒŸπŸ“š

Hey Devs! πŸ‘‹ Ever needed to switch tasks quickly without committing changes? Enter Git Stash - your secret weapon! 🌟

  1. What's Git Stash?

    • Git Stash allows you to save changes temporarily without committing.

    • Perfect for those "quick-fix" moments or unexpected context switches.

  2. How to Stash Like a Pro:

    • Use git stash save to stash your changes.

    • Apply stashed changes later with git stash apply.

  3. Why Stash?

    • Keep your working directory clean.

    • Effortlessly switch between tasks without cluttering your commit history.

Cherry-pickπŸš€πŸ’

  1. What's Cherry-Pick?

    • Git Cherry-Pick lets you choose specific commits to apply to your current branch.

    • Perfect for grabbing the juiciest updates without merging the whole branch.

  2. How to Cherry-Pick Like a Pro:

    • Use git cherry-pick <commit-hash> to select and apply a single commit.

    • Craft your codebase with only the features and fixes you need.

  3. Why Cherry-Pick?

    • Fine-tune your commits for a cleaner, customized history.

    • Ideal for integrating specific changes without the baggage.

Resolving Conflicts: It's time to master the art of Conflict Resolution! 🀝

  1. What's Conflict Resolution?

    • Conflict resolution occurs when Git encounters conflicting changes in different branches.

    • Git marks the conflicting sections, and it's your job to harmonize them.

  2. How to Resolve Conflicts Like a Pro:

    • Open the conflicted file(s) in your text editor.

    • Manually merge changes, remove conflict markers, and save.

    • Use git add <conflicted-files> to mark conflicts as resolved.

    • Complete the merge with git merge --continue.

  3. Why Master Conflict Resolution?

    • Keep your codebase clean and coherent.

    • Collaborate seamlessly even when multiple devs are making changes.

Conflicts are opportunities for collaboration. Ready to turn code clashes into victories? πŸš€πŸ”§

Now lets do some Hands-on

Task-01:

Creating a new branch (dev) and make some changes

# Create a new branch
git checkout -b dev

# Make changes to the code
# Edit files, add new files, etc.

# Stage the changes
git add .

# Commit the changes
git commit -m "Made changes on the dev branch"

Using git stash to save the changes without committing them

# Stash the changes
git stash

Switching to a different branch (div), make some changes, and commit them

# Switch to a different branch
git checkout div

# Make changes to the code
# Edit files, add new files, etc.

# Stage the changes
git add .

# Commit the changes
git commit -m "Made changes on the div branch"

Using git stash pop to bring the changes back and apply them on top of the new commits

# Switch back to the original branch
git checkout dev

# Apply the stashed changes on top of the new commits
git stash pop

Task 2 :

Adding lines to version01.txt in the development branch (dev)

# Switch to the development branch
git checkout dev

# Open version01.txt in your text editor
# Add the following lines after the previous content:
# "This is the bug fix in development branch"
# ...

# Stage the changes
git add version01.txt

# Commit the changes
git commit -m "Added feature2.1 in development branch"

Adding the next set of lines to version01.txt in the development branch (dev)

# Open version01.txt in your text editor
# Add the following lines after the previous content:
# "This is the advancement of the previous feature"
# ...

# Stage the changes
git add version01.txt

# Commit the changes
git commit -m "Added feature2.2 in development branch"

Adding the final set of lines to version01.txt in the development branch (dev)

# Open version01.txt in your text editor
# Add the following lines after the previous content:
# "Feature 2 is completed and ready for release"
# ...

# Stage the changes
git add version01.txt

# Commit the changes
git commit -m "Feature2 completed"

Reflect these changes in the production branch (prod) using rebase

# Switch to the master branch
git checkout master

# Create a new branch for production
git checkout -b prod

# Merge changes from dev into prod using rebase
git rebase dev

# Resolve any conflicts if needed
# Continue the rebase process if prompted

# Now prod contains the changes from dev
# You can push the changes to your remote repository if needed
git push origin prod

Task 3:

Identify the commit hash of "Added feature2.2 in development branch"

# Display the commit history in the development branch
git log dev

Cherry-pick the identified commit into the Production branch (prod)

# Switch to the Production branch
git checkout prod

# Cherry-pick the commit from the development branch
git cherry-pick <commit-hash>

# Resolve any conflicts if prompted
# Continue the cherry-pick process

# After cherry-picking, the changes will be applied to the Production branch

Add the requested lines after "This is the advancement of the previous feature"

# Open version01.txt in your text editor
# Add the following lines after the specified content:
# "Added few more changes to make it more optimized."

# Stage the changes
git add version01.txt

# Commit the changes
git commit -m "Optimized the feature"

πŸ’₯Conclusionβš–οΈπŸπŸ§

Our journey of day 11 into Advanced Git & GitHub for DevOps Engineers πŸš€, we've mastered complex workflows, from advanced branching strategies to cherry-picking commits 🌳. This toolkit empowers us in orchestrating smooth development pipelines πŸ› οΈ. A heartfelt thank you for your active participation in this learning adventure!

#AdvancedGit #GitHub #DevOpsEngineers #GitWorkflow #VersionControl πŸŒπŸš€ πŸ™πŸ™πŸ™Thanks for readingπŸ™πŸ™

Β