Introduction 📜:
Welcome to this exciting blog post where we dive deep into the world of Advance Git & GitHub for DevOps Engineers! As technology continues to evolve, version control systems have become an integral part of the software development process. Git, with its unparalleled features and GitHub as the leading platform for collaboration, are at the forefront of this revolution. In this blog, we'll explore some advanced Git techniques and GitHub practices that will empower DevOps Engineers to streamline their development workflows, collaborate effectively, and ensure a smooth, efficient, and error-free development cycle.🧙♂️💻
Git Branching :
Git branching is a fundamental and powerful concept in Git, the popular version control system. Branching allows developers to create isolated environments within a repository, where they can work on new features, bug fixes, or experiments without affecting the main codebase. Each branch represents an independent line of development, allowing developers to work on multiple tasks simultaneously and later merge their changes back into the main codebase.
Git Revert & Reset :
git revert
and git reset
are powerful Git commands used to undo changes in a repository's history. However, they achieve this in different ways and have distinct use cases.
- Git Revert :
git revert
is used to create a new commit that undoes the changes introduced by a specific commit or a range of commits.When you use
git revert
, you are not actually removing the original commit from the history. Instead, Git creates a new commit that represents the inverse of the changes made in the target commit(s).git revert
is a safe way to undo changes, especially when you want to preserve the history and avoid rewriting commit history.
Git Reset :
git reset
is used to move the current branch pointer to a specific commit, effectively resetting the branch's state to that commit.Unlike
git revert
,git reset
does not create new commits. Instead, it modifies the commit history by "removing" the commits after the reset point. These removed commits are not immediately visible in the log but are still present in the repository for some time (usually 30 days) as part of Git's garbage collection mechanism.git reset
is considered a more powerful and potentially dangerous command because it can lead to the loss of commit history.git reset --soft
moves the branch pointer to the specified commit while preserving the changes in the working directory and staging area.git reset --hard
moves the branch pointer to the specified commit and discards all changes in the working directory and staging area that came after the reset point.
Git Rebase and Merge📚 :
What is Rebase?
Git rebase is a command that lets users integrate changes from one branch to another, and the logs are modified once the action is complete. Git rebase was developed to overcome merging’s shortcomings, specifically regarding logs.
With rebase, you can incorporate the changes from one branch into another, effectively moving your branch to a different starting point. This helps in avoiding messy merge commits and creates a more linear and easy-to-follow history.
What is Git Merge?
Git merge is a command that allows developers to merge Git branches while the logs of commits on branches remain intact.
The merge wording can be confusing because we have two methods of merging branches, and one of those ways is actually called “merge,” even though both procedures do essentially the same thing.
Task 1:
Add a text file called version01.txt inside the Devops/Git/ with “This is first feature of our application” written inside. This should be in a branch coming from master
, [hint try git checkout -b dev
], swithch to dev
branch ( Make sure your commit message will reflect as "Added new feature"). [Hint use your knowledge of creating branches and Git commit command]
Add new commit in dev
branch after adding below mentioned content in Devops/Git/version01.txt: While writing the file make sure you write these lines
1st line>> This is the bug fix in development branch
Commit this with message “ Added feature2 in development branch”
2nd line>> This is gadbad code
Commit this with message “ Added feature3 in development branch
3rd line>> This feature will gadbad everything from now.
Commit with message “ Added feature4 in development branch
Conclusion :
Keep in mind that this blog only scratches the surface of the vast possibilities Git and GitHub offer. There are always new features, tools, and best practices emerging in the DevOps world. Stay up-to-date with the latest trends and continuously improve your skills to stay ahead in this dynamic and exciting field! 🌟