Git and GitHub Basics
Week 4: Git and GitHub Challenge - Solution
Task 1: Fork and Clone the Repository
Commands Used:
# Clone the forked repository
git clone https://github.com/<your-username>/90DaysOfDevOps.git
# Navigate into the cloned repository
cd 90DaysOfDevOps/2025/git/01_Git_and_Github_Basics
Task 2: Initialize a Local Repository and Create a File
Commands Used:
# Create a new directory for the challenge
mkdir week-4-challenge
cd week-4-challenge
# Initialize a new Git repository
git init
# Create a file and add content
vim info.txt
# Stage the file for commit
git add info.txt
# Commit the changes
git commit -m "Initial commit: Add info.txt with introductory content"
Task 3: Configure Remote URL with PAT and Push/Pull
Commands Used:
# Configure remote URL with PAT
git remote add origin https://<your-username>:<your-PAT>@github.com/<your-username>/90DaysOfDevOps.git
#If a remote named origin already exists, update it with:
git remote set-url origin https://<your-username>:<your-PAT>@github.com/<your-username>/90DaysOfDevOps.git
# Push the changes to GitHub
git push -u origin master
# Pull latest changes from remote repository (optional)
git pull origin master
Task 4: Explore Your Commit History
Commands Used:
# View commit history
git log
Task 5: Advanced Branching and Switching
Commands Used:
# Create a new branch
git checkout -b feature-update
# OR
git branch feature-update
# Switch to the new branch
git switch feature-update
# OR
git checkout feature-update
# Modify the file
vim info.txt
# Stage and commit changes
git add info.txt
git commit -m "Feature update: Enhance info.txt with additional details"
# Push the branch to remote
git push origin feature-update
After pushing, create a Pull Request (PR) on GitHub to merge feature-update into main.
Task 6: Explain Branching Strategies
Why Are Branching Strategies Important?
Branching strategies are essential in collaborative software development as they help manage code changes efficiently and minimize conflicts. Below are key reasons why they matter:
1. Isolating Features and Bug Fixes
Developers can work on new features or bug fixes in separate branches without disrupting the
mainbranch.This keeps the production-ready code stable while new updates are developed and tested.
2. Facilitating Parallel Development
Multiple developers or teams can work on different features simultaneously.
Each developer has their own working branch, preventing conflicts until their changes are merged.
3. Reducing Merge Conflicts
By keeping changes organized in branches, the risk of merge conflicts is reduced.
Frequent integration using structured workflows ensures conflicts are resolved early.
4. Enabling Effective Code Reviews
Code changes are reviewed in Pull Requests (PRs) before merging into the
mainbranch.This improves code quality and ensures best practices are followed.
Common Branching Strategies
1️⃣ Feature Branching
Each new feature gets its own branch (
feature-branch).Developers work independently and merge into
mainordeveloponce completed.
2️⃣ Git Flow
Uses multiple branches:
main(stable production code)develop(active development)feature(new features)release(preparing a release)hotfix(urgent fixes)
3️⃣ GitHub Flow
A simpler approach:
Work on a feature branch.
Open a Pull Request.
Get it reviewed and merged into
main.
4️⃣ Trunk-Based Development
Developers merge small, frequent changes directly into
mainwithout long-lived branches.Reduces complexity and speeds up releases.
Conclusion
Branching strategies enhance teamwork, prevent disruptions, and improve code quality. Choosing the right strategy depends on project size, team workflow, and release cycle.