Mastering Git and GitHub: A DevOps Engineer's Guide

Mastering Git and GitHub: A DevOps Engineer's Guide

Introduction

Welcome back to our DevOps expedition! Today, we embark on Day 10, where we delve into the advanced intricacies of Git and GitHub. As we progress, we’ll uncover the power of branching, the finesse of reverting changes, and the art of merging through real-world tasks.

Git Branching: The DevOps Sandbox

Git Branching is akin to having your own development playground. Let’s create a branch named ‘dev’ to isolate our work:

git checkout -b dev

In this ‘dev’ branch, we introduce a file, version01.txt in the Devops/Git/ directory, marked with the message "This is the first feature of our application." Commit this addition with a descriptive message like "Added new feature."

git add .
git commit -m "Added new feature"

This branch allows us to experiment, develop features, and fix bugs in a contained environment without disrupting the main repository.

Git Revert and Reset: Masters of Code Control

Enter two formidable commands: git reset and git revert. These tools empower us to modify or eradicate changes made in previous commits.

To illustrate, let’s add and commit changes to version01.txt in the 'dev' branch:

# While writing the file, ensure the following content
# 1st line >> This is the bug fix in development branch
git commit -m "Added feature2 in development branch"

# 2nd line >> This is gadbad code
git commit -m "Added feature3 in development branch"

# 3rd line >> This feature will gadbad everything from now.
git commit -m "Added feature4 in development branch"

Now, the challenge: restore the file to a previous version where the content is “This is the bug fix in development branch.” You can accomplish this using either git revert or git reset.

Git Rebase vs. Git Merge: Unraveling the Enigma

Git Rebase:

git checkout master
git pull origin master
git checkout dev
git rebase master

Git Rebase integrates changes from one branch to another, rewriting commit logs for a cleaner history.

Git Merge:

git checkout master
git pull origin master
git merge dev

Git Merge combines branches while preserving commit logs.

Conclusion

In conclusion, Day 10’s journey through Git and GitHub unveils the tools that transform DevOps engineers into code maestros. Remember, practice is key, so immerse yourself, experiment, and witness the transformation in your version control prowess. Stay tuned for more DevOps adventures, and happy coding!