Day 10 : A Comprehensive Guide to Git and GitHub: Branching, Reverting, Resetting, and More๐๐
Day#10 of 90 Days Of Devops Challenge

Experienced QA professional with a passion for manual and automation testing. Proficient in DevOps practices, ensuring seamless integration and continuous delivery. Dedicated to ensuring top-notch software quality and efficiency. Eager to contribute my skills to Hashnode's vibrant tech community. Let's collaborate and create exceptional experiences!
Introduction
๐ Hey there! Ever heard of Git and GitHub? They're like superheroes for developers ๐ฆธโโ๏ธ, making teamwork super smooth and code management a piece of cake ๐ฐ. In this blog, we're going to explore some basic ideas about Git and GitHub. We'll chat about cool stuff like branches, going back in time ๐ฐ๏ธ, fixing things, combining code, and even some magic called rebasing. By the time we're done, you'll be a pro at these tricks, ready to tackle all sorts of adventures in your coding journey! ๐
๐ฟ Git Branching for Beginners
Imagine you're painting a picture, but you want to try out two different ideas at the same time without messing up the original. Git branching is like having two separate canvases where you can work on different things without mixing them up.
When using Git branches, developers can create these separate spaces to add new features or fix bugs without affecting the main painting. Each branch is like a snapshot of the artwork that you can edit without worrying about the original version.
This makes it super simple to organize and keep track of changes while collaborating with others. It's like having a magical cloning spell for your project! ๐ช๐๏ธ
๐ฑ Creating a New Branch and Saving Changes:
๐ฟ Start by creating a new branch called "dev" from the main starting point.

๐ Put a new file named "version01.txt" inside a special place called "Devops/Git/". Inside this file, write "This is the first special part of our program."
โ๏ธ Now, tell the system that you've done something important by confirming your changes with a message that makes sense.

๐ Share your changes with others by sending them to a faraway place where everyone can see and talk about them. This is like showing your work on a big screen for review.

๐Git Revert and Reset
Here's a detailed comparison of Git Revert and Git Reset in a tabular form with emojis:
| Git Revert ๐ | Git Reset ๐ | |
| Purpose | ๐ Undo changes by creating a new commit that undoes a previous commit's changes. | ๐ Discard commits and move the branch pointer to a specific commit. |
| Commit History | ๐ Commit history remains intact, and the undoing commit is added as a new commit. | ๐ช Commit history can be rewritten, and specific commits can be removed. |
| Usage | ๐ Used when you want to keep a clear history and collaborate with others without altering the commit history. | โ ๏ธ Used for local changes and when you're certain about discarding previous commits. Not recommended for shared branches. |
| Undoing Multiple Commits | ๐ Can be used to undo multiple commits by specifying a range of commits. | ๐ Can be used to move the branch pointer to any commit, effectively discarding commits after that point. |
| Safety | ๐ก๏ธ Safer option, as it doesn't alter the existing commit history and is suitable for public repositories. | โ ๏ธ Riskier option, as it rewrites history and may lead to confusion when collaborating with others. |
| Workflow | ๐ถ Reverting commits maintains a linear history, which helps understand changes over time. | ๐ Resetting can create a more complex branch history, potentially making it harder to track changes. |
| Commands | ๐ git revert <commit> | ๐ git reset --<mode> <commit> |
| Common Use Cases | ๐ Undoing specific changes or fixing bugs while keeping a clean history. | ๐ซ Discarding local commits before they are pushed, starting over, or fixing local mistakes. |
Remember, both commands have their place in different scenarios, so choose the one that best suits your needs and the context of your project! ๐ค
๐งฉGit Rebase and Merge
Here's a detailed comparison of Git Rebase and Git Merge in a tabular form with emojis:
| Aspect | Git Rebase | Git Merge |
| ๐ Purpose | Incorporates changes from one branch into another while maintaining a linear commit history. | Combines changes from one branch into another while preserving the original branch's history. |
| ๐ Commit History | Creates a cleaner, more linear history by replaying commits on top of the target branch. | Preserves the commit history of both branches, resulting in a more branching and merging-like history. |
| ๐งฉ Branch Structure | Can make the branch structure appear more straightforward and easier to follow. | Results in a more branching-like structure that shows the separate development paths. |
| ๐ Base Commit | Commits are based on the latest commit of the target branch, making integration smoother. | Creates a new commit with two parent commits, preserving the divergence point. |
| โณ Time Complexity | This can lead to more conflicts and requires careful handling. | Generally results in fewer conflicts but may clutter the history. |
| ๐ ๏ธ Interactive Mode | Allows interactive editing of commits during the rebase process. | Doesn't offer an interactive mode. |
| ๐ง Use Cases | Ideal for feature branches and topic branches where a linear history is preferred. | Suited for integrating larger and more complex features or bug fixes from one branch to another. |
| ๐ Advantages | Produces a cleaner, more logical commit history. | Preserves the entire development path and can provide a clearer view of individual branch changes. |
| โก Disadvantages | Can be complex and lead to conflicts if not handled properly. | This may create a more cluttered history, especially when dealing with frequent merges. |
| ๐ Collaboration | Requires more communication and coordination among team members due to history rewriting. | Easier to understand for distributed teams and doesn't require as much coordination. |
| ๐ Execution | Commands like git rebase or interactive tools initiate the process. | Commands like git merge bring changes from one branch into another. |
Remember, both Git Rebase and Git Merge have their use cases and advantages. The choice depends on your team's preferences, the project's needs, and your desired commit history structure. Feel free to pick the one that suits your development workflow best! ๐
๐Task 1: Adding and Modifying Commits
โAdd more content to the file version01.txt and commit the changes as requested:

โ Restore the file to a previous version:
Using git revert

Using git reset

Note: Be cautious when using
git resetas it rewrites history. It's generally safer to usegit revert.
โ
Push the changes from your local dev branch to the remote repository:
๐ Task 2: Exploring Branches and Collaboration
โ Create multiple branches, make changes
โ
Add changes to the dev branch and merge it into master

โ Try out git rebase

๐Conclusion
Understanding Git branching, reverting, resetting, merging, and rebasing is essential for effective collaboration and version control in software development. By mastering these concepts, you'll be better equipped to manage projects, work on different features simultaneously, and maintain a clean commit history. With Git and GitHub at your fingertips, you have the tools to streamline your development workflow and enhance code quality.
Happy git-ing!๐๐
Thank you for taking the time to read this blog. I hope you found the information helpful and insightful. So please keep yourself updated with my latest insights and articles on DevOps ๐ by following me on :
Hashnode: vishaltoyou.hashcode.dev
LinkedIn: linkedin.com/in/vishalphadnis
So, Stay in the loop and stay ahead in the world of DevOps!
Happy learning ๐๐๐ง๐ฆ๐ง๐ ๏ธ๐ป๐ผ๐๐๐๐๐๐




