0% found this document useful (0 votes)
2 views15 pages

Git Basic Notebook

The document outlines essential Git workflows for team collaboration, emphasizing best practices for version control, hotfixes, rollbacks, and maintaining a clean commit history. It provides a structured approach to collaboration, including key commands and strategies for handling conflicts and ensuring accountability. Additionally, it discusses various branching strategies suitable for different team sizes and project complexities.

Uploaded by

mohammad.ahmed09
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views15 pages

Git Basic Notebook

The document outlines essential Git workflows for team collaboration, emphasizing best practices for version control, hotfixes, rollbacks, and maintaining a clean commit history. It provides a structured approach to collaboration, including key commands and strategies for handling conflicts and ensuring accountability. Additionally, it discusses various branching strategies suitable for different team sizes and project complexities.

Uploaded by

mohammad.ahmed09
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Essential Git Workflows

Best practices for team collaboration and version control

   
COLLABORATION HOTFIXES ROLLBACKS CLEAN HISTORY
Collaborating on a Team Project

 Use Case
 Team of architects designing a skyscraper

 Each architect works on different floors

 Git acts as the master blueprint

 Why Git?
 Structured workflow prevents chaos

 Like a project diary tracking every change

 See who built what, when, and why


 Key Benefits
 Parallel development without conflicts
 Collaboration Process
 Complete history of all changes

1 2 3 4 5  Accountability for every modification


Clone Create Branch Make Changes Commit & Push Merge to Main
 Easy rollback to previous versions
Repository
Team Collaboration Considerations

 Consistent Naming  Frequent Commits

 Agree on clear branch naming system  Save work in small, logical chunks

 Use prefixes for different types  Write clear, descriptive messages

 Include ticket numbers when applicable  Commit often to track progress

 Library Analogy  Diary Analogy


Like a library's Dewey Decimal System — organized and predictable "Designed the lobby entrance" vs. "Did stuff"

 Pull Requests  Conflict Resolution

 Treat as peer reviews  Expect merge conflicts to happen

 Inspect before adding to master  Communicate with team members

 Discuss improvements and give approval  Decide together on final solutions

 Team Review Analogy  Architecture Analogy


Like architects reviewing blueprints before construction Two architects placing a window in the same spot
Git Toolkit: Essential Commands

Your essential tools for seamless team collaboration

 git clone  git pull  git checkout -b

Download the Blueprint Get the Latest Updates Create Your Sandbox
Creates a personal copy of the entire project on Syncs your local blueprint with the latest Creates an isolated workspace for building
your local machine changes from the team your feature

 git add  git commit -m  git push

Prepare for Review Save with a Note Share Your Masterpiece


Selects which changes to include in your next Takes a snapshot of your changes with a Uploads your work to the central server for
save point descriptive message team review

    

Clone Branch Commit Push Merge


Handling Hotfixes on a Live Site

 Critical Scenario
 Banking app security flaw discovered

 Users can see each other's balances

 Need immediate fix without disrupting development

 Why Git?

 Parallel universes approach to development

 Isolate urgent fixes from ongoing features  Hotfix Process

 Rapid deployment of critical patches


1 2 3 4

Create hotfix Apply & test the fix Merge to main & Merge to develop
 Stability  Speed branch from main deploy branch

 Collaboration  Traceability
 Remember
 Always merge hotfixes back into development branch

 Prevents bugs from reappearing in future releases


Hotfix Considerations

Key strategies for effective emergency fixes

 Branching Strategy  Sync Branches  Clear Naming

 Create hotfix branches from main  Always merge hotfix back to develop  Use hotfix/ prefix

 Test rigorously before deployment  Prevents reappearing bugs  Include specific issue description

 Merge to both main and develop  Maintains consistency across  Make names urgently clear
codebase

 Code Red Protocol  Leaky Pipe Analogy


 Example
Like emergency procedures in a hospital Fixing a leak in your house but not
— everyone knows their role when crisis updating the building blueprint — same hotfix/critical-balance-leak clearly
strikes leak will return in next renovation communicates urgency and purpose

   

Create Hotfix Apply Fix Deploy Sync Branches


Emergency Response Kit

Critical commands for hotfix deployment

 git checkout -b hotfix/bug-fix main  git commit -m "Hotfix:..."

 Enter the Emergency Room  Apply the Surgical Fix

 Creates isolated branch  Precise message for audit trail

 Based on stable code  Documents what was fixed

 Away from development chaos  Explains why the fix was needed

 Example
 Example git commit -m "Hotfix: Patched critical balance
git checkout -b hotfix/security-patch main visibility bug"

 git checkout main & git merge & git push  git checkout develop & git merge

 Deploy the Cure  Inform the Research Team

 Switch to main branch  Switch to develop branch

 Merge the fix  Merge same fix

 Push to deploy immediately  Prevents future reappearance

 Example
git checkout main  Example
git merge hotfix/security-patch git checkout develop
git push git merge hotfix/security-patch

   

Create Branch Commit Fix Deploy Sync Branches


Rolling Back a Buggy Release

 Critical Scenario
 New auto-save feature launched

 Corrupting user data unexpectedly

 Fix isn't immediately obvious

 Why Git?

 Ultimate safety net for your project

 Complete history of all changes  Rollback Process


 Time travel to any previous state
1 2 3 4

Identify Problem Choose Method Execute Rollback Communicate


 Stability  Quick Recovery

Revert vs. Reset


 User Trust  Debugging Aid
 git revert  git reset
 Creates new commit  Rewrites history
 Preserves history  Discards commits
 Safe for shared branches  Use with caution
Rollback Considerations

Key strategies for safe and effective rollbacks

 Revert vs. Reset  Communication  Identify the Cause

 git revert — diplomatic option  Announce rollback to team  Use git log to find problematic
commit
 git reset — brute force option  Provide clear instructions
 Pinpoint exact source of issue
 Use revert for shared branches  Document reason for rollback
 Don't revert blindly

 Key Differences

 git revert  git reset


 Team Announcement  Command Example
Creates new Erases commits
commit that from history, "Attention everyone, I've rolled back git log --oneline --graph
undoes changes dangerous for the auto-save feature. Please pull the
while preserving shared branches latest changes from the main Visualize commit history to identify
history
branch." when the bug was introduced

   

Identify Choose Communicate Execute


Method
Time Traveler's Console

Essential commands for rolling back changes

git reset --hard


 git log --oneline  git revert [commit-ID]  [commit-ID]

 Time Machine's Dashboard  Safe Undo Button  'Scrap It All' Lever


 Clean list of commits  Creates new commit  Rewrites history

 Chronological view  Reverses changes safely  Discards commits

 Each line is a save point  Preserves history  Dangerous for shared branches

 Warning
 Example  Example Only use on private branches, never on
git log --oneline --graph git revert a1b2c3d shared ones like main

   

Identify Commit Choose Method Execute Push Changes


Command
Maintaining a Clean Commit History

 Use Case
 Building a search feature

 Messy commits: "started search", "oops typo"

 Clean up to: "feat: Implement search"

 Why Git?

 Well-written novel — clear story of project evolution

 Easier to understand progression of features

 Simpler debugging and code review


 Cleaning Process
a1b2c3d started search
e4f5g6h oops typo
1 2 3 4

i7j8k9l fix alignment Make Small Interactive Rebase Squash Related Clear Messages
Commits
↓ feat: Implement search functionality

 Better Readability  Easier Reviews

 Simpler Debugging  Team Collaboration


Clean History Considerations

Best practices for maintaining a readable commit history

Don't Rebase Shared  Commit Messages  Squash on Merge



Branches

 Adopt team-wide style guide  Configure GitHub repository settings


 Rewriting history is a solo activity
 Use Conventional Commits format  "Squash and merge" pull requests
 Only on private branches before
sharing  Add structure and predictability  Keep main history focused on
features
 Never on shared branches like main

 Message Format

feat: add search


functionality
 Book Analogy  Repository Settings

Like publishing a revised edition feat: fix: docs: style: Enable "Allow squash merging" in
while people are still reading the first repository options to automatically
one — creates chaos refactor: test: combine commits

   

Create Branch Make Clean History Merge to Main


Commits
Storyteller's Tools

Essential commands for crafting a clean commit history

 git rebase -i HEAD~4  git commit --amend  git merge --squash

 The Story Editor  "One More Thing" Fix  Chapter Summary

 Interactive rebase editor  Update last commit  Combine all commits

 Reorder commits  Change message or add files  Single commit on main

 Squash related commits  Avoid "oops" commits  Clean history for features

 Example  Example
 Example git commit --amend -m "Fixed git merge --squash feature-
git rebase -i HEAD~3 typo in search" branch

   

Create Branch Edit History Squash Merge Clean


Commits
Git Branching Strategies
 Use Case  Strategy Comparison
Choose the right branching model for your team's workflow Feature Git Flow GitHub Flow GitLab Flow

Complexity High Low Medium


 Key Factors
Release Versioned Continuous Environment-based
Team Size Release Cycle
 Small vs. Large teams
 Continuous vs. Scheduled Best for Large projects Small teams DevOps teams

Hotfix support   
Deployment Project
 Process complexity
 Complexity & scale

 Key Strategies

 Git Flow  GitHub Flow  GitLab Flow


Strict branching model Simpler model Hybrid approach
master develop feature release main feature pull requests main environment feature

hotfix

 Setup Commands

 Git Flow  GitHub Flow  GitLab Flow


git flow init git checkout -b [feature] main git checkout -b [feature] main

git flow feature start [name] gh pr create git merge [feature] production
Resolving Merge Conflicts

 Types of Conflicts  Resolution Commands

Content Delete/Modify git status git diff


   
Show files with conflicts Show differences

 git log --merge  git merge --


Show conflicting abort
 Binary Files  Tree
commits Cancel merge

+ git add  git mergetool


Mark as resolved Launch merge tool
 Resolution Process

1 2 3 4 5
 Conflict Markers
Identify Conflicts Open Files Resolve Changes Stage Files Commit

<<<<<<< HEAD
function calculate() {
 Best Practices return a + b;
}

 Communicate Changes  Small Commits =======


function calculate() {
return (a + b) * 0.9;
 Pull Often  PR Reviews
}
>>>>>>> branch-name
 Remember  Edit between markers to resolve
Conflicts are normal in collaboration. The key is to communicate and resolve them quickly.

 Common Conflict Causes

You might also like