
Git Branching:
Branches: Isolate development work without affecting other branches.
Default Branch: Each repository has one default branch (often named “master” or “main”).
Multiple Branches: Repositories can have multiple other branches (e.g., feature branches).
Merging: You can merge a branch into another using pull requests.
Git Revert and Reset:
git reset: Removes or edits changes made in previous commits.
git revert: Allows you to undo specific commits while preserving history.
Git Rebase and Merge:
Git Rebase:
Integrates changes from one branch to another.
Modifies commit logs.
Overcomes merging limitations.
Git Merge:
Merges branches while keeping commit logs intact.
Confusingly, both methods are called “merge.”
Let's practice these essential Git concepts.
Task 1: Branching and Reverting
Objective: Create a new branch, make changes, and then revert those changes using Git.
Create a New Branch:
Create a branch named “feature-branch” from the existing “main” branch.
Use the following command:
git checkout -b feature-branch
Add a File:
Inside the newly created branch, add a text file named
feature.txt.Write some content in the file (e.g., “This is a new feature!”).
Commit your changes with an appropriate message (e.g., “Added feature to feature-branch”).
Oops! A Bug Crept In:
Realize that there’s a bug in your feature. The content should have been “This is a fantastic feature!” instead.
Panic mode: Activate!
Revert the Change:
Use either
git revertorgit resetto undo the last commit (the incorrect content).Make sure the content in
feature.txtis now “This is a fantastic feature!”
Push Your Branch:
- Push your local branch to the remote repository (e.g., GitHub).
Task 2: Rebase and Merge
Objective: Demonstrate Git rebase and merging between branches.
Create Two Feature Branches:
Create two branches: “feature1” and “feature2.”
In each branch, add a file (e.g.,
feature1.txtandfeature2.txt) with some content.Commit your changes in both branches.
Merge Feature1 into main:
Switch back to the “main” branch.
Merge the changes from “feature1” into “main”:
git merge feature1
Rebase Feature2 onto main:
Still in the “main” branch, rebase “feature2” onto it:
git checkout feature2 git rebase main
Observe the Differences:
- Compare the commit history and logs after merging and rebasing.
Thank you for reading😉.



