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)
- Clone the repository:
git clone https://github.com/vaishnosingh/webb.git cd webb - Install dependencies:
npm install - 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:
- Check what changed:
git status - Stage and commit your work:
git add . git commit -m "feat: worked on components from home" - Push to GitHub:
(If prompted for credentials: username = your GitHub username, password = your GitHub Personal Access Token).
git push origin main
🏢 When You Arrive at the Office
Before making any edits, download the updates you made at home:
- Open terminal in the project directory:
cd /home/creserver/Desktop/WEBB - Pull latest changes:
(If you added any new npm packages at home, run
git pull origin mainnpm install) - 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"
- Morning / Start:
git pull origin main- 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?
- Safety & Zero Risk: If an experiment goes wrong, you simply delete the branch. Your
mainsite stays completely untouched. - Multiple Tasks Simultaneously: Work on a big feature on a branch without blocking quick hotfixes on
main. - 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:
- Create and switch to a feature branch:
git checkout -b redesign-pricing - Make your code edits and test them locally:
npm run dev - Commit your changes on the branch:
git add . git commit -m "feat: experimental pricing layout" - 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:
(Your project instantly returns to the stable working state!)
git checkout main git branch -D redesign-pricing
- If you love it and want to keep it:
🧰 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