Hey DevOps enthusiasts! 🌐✨
First off, a sincere apology for the brief hiatus. Life got a bit hectic, and I took a few days off from our DevOps journey. But hey, we're back, and I'm thrilled to catch you up on all the incredible insights and discoveries we've missed over the past few days. Ready to dive back into the #90DaysOfDevOps Challenge?
Let's pick up right where we left off and explore the highlights of Days 10 to 15. From tackling new tools to overcoming challenges, it's been quite a ride. Thanks for your understanding, and without further ado, let's get back to the DevOps adventure!
Day 10: Advance Git & GitHub for DevOps Engineers.
🌐 Understanding Git Branching, Revert & Reset, Rebase & Merge 🌐
Git Branching:
In Git, branches are powerful tools for isolating development work. They allow developers to work on features, bug fixes, or experiments in a contained area without affecting the main codebase. The default branch is usually 'master' or 'main,' and additional branches can be created for specific tasks. Merging branches is achieved through pull requests, ensuring a smooth integration of changes.
Git Revert & Reset:
Both git revert
and git reset
are tools for managing changes in previous commits.
git revert
: This command creates a new commit that undoes changes from a previous commit, maintaining a clear history. It's useful when you want to keep a record of the changes you're reverting.git reset
: This command is more powerful; it erases commits from the current branch. It's ideal for situations where you want to completely remove or rework the commit history.
Git Rebase & Merge:
Both Git rebase and merge are used to integrate changes from one branch into another, but they differ in how they modify commit logs.
Git Rebase: This command integrates changes and modifies commit logs, offering a cleaner and more linear history. It's useful for maintaining a tidy project history, especially when working on feature branches.
Git Merge: The merge command combines changes from different branches while preserving the original commit history. It's a straightforward way to integrate changes, and it's especially useful for merging feature branches into the main branch.
For a deeper understanding of Git Rebase and Merge, check out this article.
DevOps Day 10: Advanced Git & GitHub Tasks:
Task 1: Git Branching, Revert, and Reset
Creating and Committing in a New Branch:
Command:
git checkout -b dev
Explanation: This command creates a new branch named 'dev' and switches to it. Then, a new file
version01.txt
is added in theDevops/Git/
directory with the specified content. Finally, the changes are committed, marking the addition of a new feature.
Pushing Changes to Remote Repository:
Command:
git push origin dev
Explanation: This command pushes the 'dev' branch and its changes to the remote repository. It ensures that the changes made locally are reflected on the remote repository, allowing collaboration with others.
Adding Commits in the 'dev' Branch:
Commands:
git checkout dev echo "This is the bug fix in development branch" >> Devops/Git/version01.txt git commit -am "Added feature2 in development branch"
- Explanation: These commands switch to the 'dev' branch, add new content to
version01.txt
as specified, and commit the changes with appropriate messages. This simulates the development of additional features in the 'dev' branch.
- Explanation: These commands switch to the 'dev' branch, add new content to
Restoring to a Previous Version:
Command (Using Git Revert):
git revert HEAD~3..HEAD
Explanation: This command uses
git revert
to undo the last three commits on the 'dev' branch. It creates new commits that revert the changes, preserving the commit history.Command (Using Git Reset):
git reset HEAD~3 --hard
Explanation: This command uses
git reset
to remove the last three commits on the 'dev' branch. The--hard
option discards changes, resetting the branch to a previous state.
Task 2: Branch Demonstration, Merge, and Rebase
Demonstrate Branches:
Commands:
git branch feature1 git branch feature2 git checkout feature1 # Add changes to feature1 git checkout feature2 # Add changes to feature2 git checkout master git merge feature1 git merge feature2
Explanation: This sequence of commands creates two new branches, 'feature1' and 'feature2,' and demonstrates isolated development. Changes are added to each feature branch, and finally, both branches are merged into the 'master' branch.
Git Rebase:
Commands:
git checkout feature1 # Add changes to feature1 git checkout master git rebase feature1
Explanation: This sequence demonstrates the use of
git rebase
to integrate changes from 'feature1' into 'master.' It rewrites the commit history for a cleaner, more linear timeline.
🚀 DevOps Day 11: Advanced Git & GitHub[Part-2] 🚀
Let's delve deeper into Git Stash, Cherry-pick, and Resolving Conflicts:
Git Stash:
Git stash is a useful command for temporarily shelving changes in your working directory. It allows you to save your modifications without committing them, making it easier to switch branches or work on different tasks without affecting your current work.
Usage:
Saving Changes: Use
git stash
to save your changes.Viewing Stashes: You can view the list of stashes with
git stash list
.Applying Stashes: Apply the most recent stash with
git stash pop
.Deleting Stashes: Use
git stash drop
to remove a specific stash, orgit stash clear
to remove all stashes.
Cherry-pick:
Git cherry-pick enables you to select specific commits from one branch and apply them to another. This feature is particularly useful when you want to incorporate specific changes from one branch into another without merging the entire branch.
Usage:
Selecting Commits: Use
git cherry-pick <commit_hash>
to select specific commits.Applying to Another Branch: Cherry-picked commits are applied to the current branch.
Resolving Conflicts: Conflicts may occur if the cherry-picked commits conflict with changes in the target branch.
Resolving Conflicts:
Conflicts in Git occur when there are conflicting changes between branches that Git cannot automatically resolve. Conflicts typically arise during merge or rebase operations.
Identifying Conflicts:
Use
git status
to identify files with conflicts.Use
git diff
to view the conflicting changes.
Resolving Conflicts:
Manually edit the conflicted files to resolve conflicts.
Use
git add
to stage the resolved files.Complete the merge or rebase process by committing the changes.
Conflict Resolution Tools:
- Git provides various tools to help resolve conflicts, including merge tools and diff viewers.
Understanding how to manage conflicts is essential for maintaining a clean and stable codebase during collaborative development.
By mastering Git stash, cherry-pick, and conflict resolution techniques, you gain greater control over your version control workflow, ensuring smooth collaboration and efficient code management in your projects.
DevOps Day 11: Advanced Git & GitHub: Part-2 Tasks:
Task-01: Git Stash and Switching Branches
1. Create a new branch and make changes:
Command:
git checkout -b feature-branch
Explanation:
Creates a new branch named
feature-branch
.Switches to the new branch to isolate changes.
2. Use git stash:
Command:
git stash
Explanation:
Stashes the changes made in the
feature-branch
without committing them.Useful for saving work temporarily.
3. Switch to a different branch, make changes, and commit:
Command:
git checkout another-branch # Make changes to files git commit -m "Committing changes in another-branch"
Explanation:
Switches to a different branch (
another-branch
in this case).Makes changes to files and commits them.
4. Use git stash pop:
Command:
git stash pop
Explanation:
Applies the stashed changes from
feature-branch
on top of the new commits inanother-branch
.Helps in continuing the work in
feature-branch
without losing the changes made inanother-branch
.
Task-02: Versioning in Production Branch
1. Add lines in version01.txt in the development branch:
Action:
- Edit the
version01.txt
file in the development branch.
- Edit the
2. Commit these changes:
Command:
git add version01.txt git commit -m "Added feature2.1 in development branch" # Repeat for other commits
Explanation:
Adds and stages changes made in
version01.txt
.Commits the changes with meaningful messages.
3. Reflect commit messages in the Production branch:
Command:
git checkout Production git rebase Master
Explanation:
Switches to the
Production
branch.Rebases it onto the
Master
branch to incorporate the commit messages from the development branch.
Task-03: Cherry-pick in Production Branch
1. Cherry-pick a specific commit:
Command:
git checkout Production git cherry-pick <commit_hash>
Explanation:
Switches to the
Production
branch.Cherry-picks a specific commit
<commit_hash>
from the development branch.
2. Make additional changes:
Action:
- Add new lines after "This is the advancement of the previous feature" in
version01.txt
.
- Add new lines after "This is the advancement of the previous feature" in
3. Commit the changes:
Command:
git add version01.txt git commit -m "Optimized the feature"
Explanation:
Adds and stages new changes made in
version01.txt
.Commits the changes with the message "Optimized the feature."
Wrapping Up: Days 10 & 11 of 90DaysOfDevOps
As we conclude this leg of our 90DaysOfDevOps journey, we've delved into the intricacies of advanced Git and GitHub practices. Days 10 and 11 have been pivotal, introducing us to the power of Git stash, cherry-pick, and conflict resolution. These tools, when wielded with precision, empower us to navigate the complex landscape of version control and collaboration seamlessly.
Day 10: We demystified Git branching, explored the art of reverting and resetting changes, and unfolded the nuances of Git rebase and merge. With each command, we gained a deeper understanding of how to sculpt our version history with finesse.
Day 11: Advanced Git maneuvers continued as we seamlessly switched branches using Git stash, synchronized versioning between branches, and cherry-picked specific commits for precise feature integration. Conflict resolution became second nature, ensuring a harmonious collaboration process.
As we bid adieu to Days 10 and 11, the pages of our DevOps journey turn towards new horizons. Stay tuned for Day 12, where fresh challenges await.
Stay Cool, Stay humble. Happy Coding.