Files
webb/GIT_README.md

5.6 KiB

Git Guide: Cross-Machine Workflow & Branching

This guide covers the daily Git workflow for working on the WEBB project across multiple locations (Office & Home), as well as an introduction to Git Branching for safe experimenting.


🔄 1. Daily Multi-Location Workflow (Office 🏢 ↔ Home 🏠)

Follow this exact loop to keep your work completely synchronized between your office machine and home machine without merge conflicts.

                  ┌──────────────────────┐
                  │    GitHub Remote     │
                  │   vaishnosingh/webb  │
                  └──────────┬───────────┘
                    ▲                  ▲
       git push     │                  │   git push
     (leave office) │                  │ (leave home)
                    │   git pull       │   git pull
                    │ (arrive office)  │ (arrive home)
                    ▼                  ▼
             ┌──────────────┐   ┌──────────────┐
             │ Office PC 🏢 │   │  Home PC 🏠  │
             └──────────────┘   └──────────────┘

🏠 At Home (First Time Setup)

  1. Clone the repository:
    git clone https://github.com/vaishnosingh/webb.git
    cd webb
    
  2. Install dependencies:
    npm install
    
  3. Start the local server:
    npm run dev
    

🏠 When You Finish Working at Home

Before stepping away or turning off your home computer, push your work to GitHub:

  1. Check what changed:
    git status
    
  2. Stage and commit your work:
    git add .
    git commit -m "feat: worked on components from home"
    
  3. Push to GitHub:
    git push origin main
    
    (If prompted for credentials: username = your GitHub username, password = your GitHub Personal Access Token).

🏢 When You Arrive at the Office

Before making any edits, download the updates you made at home:

  1. Open terminal in the project directory:
    cd /home/creserver/Desktop/WEBB
    
  2. Pull latest changes:
    git pull origin main
    
    (If you added any new npm packages at home, run npm install)
  3. You are now working directly from where you left off at home!

🏢 When You Finish Working at the Office

Before leaving the office:

git add .
git commit -m "feat: updates made at the office"
git push origin main

🌟 The Golden Rule

"Pull before you Start, Push before you Leave"

  1. Morning / Start: git pull origin main
  2. Evening / Finish: git add . && git commit -m "..." && git push origin main

🌿 2. Understanding Git Branching

What is a Branch?

In Git, branching is like making a safe, parallel sandbox of your website. It allows you to build features or test redesigns without any risk of breaking your main, working website.

  • main (The Trunk): The stable, production-ready website code.
  • Feature Branch (The Sandbox): An isolated duplicate where you experiment freely.
main:                  ●──────●────────────────────────● (Merge back)
                               \                      /
feature-redesign:               ●──────●─────────────● (Safe experimenting)

Why Use Branches?

  1. Safety & Zero Risk: If an experiment goes wrong, you simply delete the branch. Your main site stays completely untouched.
  2. Multiple Tasks Simultaneously: Work on a big feature on a branch without blocking quick hotfixes on main.
  3. Clean Version History: Each feature or experiment has its own organized log of commits.

🛠️ Everyday Branching Cheat Sheet

Task Command
Create and jump into a new branch git checkout -b feature-name
List all branches (highlights current) git branch
Switch back to the main branch git checkout main
Merge branch work into main git merge feature-name
Delete feature branch when done git branch -d feature-name
Discard branch without saving git branch -D feature-name

🎯 Real Example with Your Website (WEBB)

Suppose you want to try a new redesign for the Pricing Page:

  1. Create and switch to a feature branch:
    git checkout -b redesign-pricing
    
  2. Make your code edits and test them locally:
    npm run dev
    
  3. Commit your changes on the branch:
    git add .
    git commit -m "feat: experimental pricing layout"
    
  4. Choose your outcome:
    • If you love it and want to keep it:
      git checkout main
      git merge redesign-pricing
      git push origin main
      
    • If you don't like it and want to scrap it:
      git checkout main
      git branch -D redesign-pricing
      
      (Your project instantly returns to the stable working state!)

🧰 3. Troubleshooting & Quick Fixes

If you forgot to pull before editing:

If you edited code locally before pulling and Git says you have local changes:

git stash             # Temporarily sets your local edits aside
git pull origin main  # Gets the latest code from GitHub
git stash pop         # Re-applies your local edits on top

Save credentials so you don't retype tokens:

git config --global credential.helper store