Advanced Git & GitHub for Successful DevOps
What is Git Branching?
Git Revert and Reset
Git Rebase and Merge
Imagine you're playing a video game, and you make a save point before a big decision. You can play the game from the save point and see what happens with different choices. If you don't like the outcome, you can always go back to the save point and try a different choice. In git, branching is like making save points and trying different paths.
These analogies show how branching in git allows you to try different things, work on different parts of a project at the same time, and combine your efforts later.
Git Revert and Reset
Think of your project as a puzzle. You put a piece in the wrong spot. Instead of taking apart the whole puzzle, you just move that one piece back to where it was before. "Git revert" lets you fix one mistake without disturbing the rest of your project.
Think of your project as a drawing. If you make a lot of changes and don’t like any of them, you might decide to erase everything back to an earlier stage. "Git reset" is like erasing your drawing to go back to a point where you liked it.
Git Rebase and Merge
Imagine you wrote a story, and later your teacher gives you a new beginning for it. "Git rebase" is like taking the middle and end of your story and attaching them to this new beginning, so your story flows better.
Key Difference:"
Merge keeps the history of both branches, showing that they were combined.
Rebase rewrites the history to make it look like your changes were made on top of the new base, making it cleaner but altering the timeline.
The syntax for reverting a commit is simple:
The syntax for Git merge a commit is simple:
Task 1 : Create a text file called version01.txt
inside the Devops/Git/
directory with the content "This is the first feature of our application."
Create a new branch called dev
from the master
branch.
Add and commit the changes in the dev
branch.
Push the dev
branch to the remote repository for review
Add and commit the changes in the dev
branch.
Push the dev
branch to the remote repository for review.
Add new commits in the dev
branch by editing the version01.txt
file as described:..
To restore the file to a previous version where the content is "This is the bug fix in the development branch," you can use the git reset
command.
if you prefer to keep the changes and revert the commit without losing the work, you can use git revert
instead of git reset
.
Subscribe to my newsletter
Read articles from Pratibha ghosh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by