#day10 of #90daysofDEVOPS
Welcome back to our DevOps journey! Today, on Day 10, we’re diving deep into the fascinating world of Git and GitHub. As we navigate through, we’ll discover the magic of branching, the skill of reverting changes, and the craft of merging using practical scenarios.
Git Branching: The DevOps Sandbox
Git Branching is like having your own playground for development. Let’s kick things off by creating a branch called ‘dev’ to keep our work separate:
git checkout -b dev
Now, in this ‘dev’ branch, we’ll add a file, version01.txt, to the Devops/Git/ directory. This file will mark the beginning of our application’s journey with the message “This is the first feature of our application.” Let’s capture this addition with a message that says “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
Now, let’s explore two powerful commands: git reset and git revert. These commands give us the ability to tweak or undo changes made in earlier commits.
To demonstrate, let’s make some changes to version01.txt in the ‘dev’ branch:
# As we're writing the file, make sure to include 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 not good code
git commit -m "Added feature3 in development branch"
# 3rd line >> This feature will cause issues from now on.
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.
In summary, our exploration of Git and GitHub on Day 10 has revealed the tools that elevate DevOps engineers to coding wizards. Remember, practice makes perfect, so dive in, experiment, and watch your version control skills soar. Keep an eye out for more exciting DevOps escapades ahead, and happy coding!