Skip to main content

Command Palette

Search for a command to run...

Embracing Git: A DevOps Journey ๐Ÿš€

Published
โ€ข2 min read
Embracing Git: A DevOps Journey ๐Ÿš€

Introduction

Git, the cornerstone of version control, plays a pivotal role in the DevOps workflow. In this blog post, we'll embark on a journey to add, commit, and manage changes in a Git repository, showcasing the power of branching, committing, and version control.

Setting the Stage

Imagine a DevOps engineer working on a project. Let's start by creating a new branch called dev from the master branch. This branch will house our exciting new features.

git checkout -b dev

Step 1: Adding the First Feature ๐ŸŽ‰

Local Repository

We begin by creating a text file named version01.txt inside the Devops/Git/ directory. Open this file and write the initial feature content.

echo "This is the first feature of our application" > Devops/Git/version01.txt

Next, let's commit this change to the local repository.

git add Devops/Git/version01.txt
git commit -m "Added new feature"

Remote Repository

Now, let's push our branch and changes to the remote repository for review.

git push origin dev

Step 2: Adding More Features ๐Ÿš€

Now that our first feature is in place, let's enrich it with additional commits.

# 1st Commit
echo "This is the bug fix in development branch" >> Devops/Git/version01.txt
git add Devops/Git/version01.txt
git commit -m "Added feature2 in development branch"

# 2nd Commit
echo "This is gadbad code" >> Devops/Git/version01.txt
git add Devops/Git/version01.txt
git commit -m "Added feature3 in development branch"

# 3rd Commit
echo "This feature will gadbad everything from now." >> Devops/Git/version01.txt
git add Devops/Git/version01.txt
git commit -m "Added feature4 in development branch"

After these commits, push the changes to the remote repository.

git push origin dev

Step 3: Rollback to a Previous Version โช

Sometimes, we need to revert changes. Let's say we want to revert to the version where the content is "This is the bug fix in development branch."

git log
# Note the commit hash of the version you want to revert to

git revert <commit-hash>

This command creates a new commit that undoes the changes made in the specified commit.

Conclusion ๐ŸŒ

In this blog post, we explored the Git commands necessary for adding features, making commits, pushing changes to the remote repository, and reverting to previous versions. Git empowers DevOps engineers to collaborate seamlessly, ensuring a robust and controlled development process.

Remember, the ability to navigate Git effectively is a key skill in the DevOps world. Happy coding! ๐Ÿš€