惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
月光博客
月光博客
MyScale Blog
MyScale Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
P
Proofpoint News Feed
人人都是产品经理
人人都是产品经理
Last Week in AI
Last Week in AI
罗磊的独立博客
G
Google Developers Blog
Y
Y Combinator Blog
博客园 - 【当耐特】
WordPress大学
WordPress大学
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
J
Java Code Geeks
酷 壳 – CoolShell
酷 壳 – CoolShell
V
Visual Studio Blog
美团技术团队
宝玉的分享
宝玉的分享
Jina AI
Jina AI
小众软件
小众软件
T
Tailwind CSS Blog
A
About on SuperTechFans

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How to Sync a Forked Git Repository (Without Losing Local...
Amandeep Singh · 2026-06-20 · via DEV Community

Amandeep Singh

If you are working on a fork of an open-source project or an organization's central repository, you will frequently need to pull down updates from the original source. This setup is the most common workflow for individuals contributing to open-source projects, where you do not have direct write access to the primary codebase and instead submit contributions via Pull Requests from your fork.

Here is a quick guide on how to safely switch to your main branch, check for updates, and sync your fork with the upstream repository—all while keeping your local uncommitted work intact.


Understanding Remotes: Origin vs. Upstream

When working with a Git fork, your project interacts with two different remote locations on GitHub:

  • origin: This points to your personal fork of the repository (e.g., git@github.com:your-username/sundar-gutka-react.git). You have read and write permissions to this remote, meaning you can push branches, make releases, and work directly here.
  • upstream: This points to the original source repository that you forked from (e.g., https://github.com/KhalisFoundation/sundar-gutka-react.git). You generally only have read permissions here. You fetch official releases and pull updates from upstream to stay in sync with the central development.

Visualizing the flow:

graph TD
    Upstream["Upstream (Original Source Repo)"] -->|"Fork on GitHub"| Origin["Origin (Your Forked Repo)"]
    Origin -->|"Clone locally"| Local["Local Machine (Your Workspace)"]
    Local -->|"git pull upstream"| Upstream
    Local -->|"git push origin"| Origin
    Origin -->|"Pull Request"| Upstream


The Sync Workflow

Here is the step-by-step process of adding the upstream remote, stashing local changes, pulling the source updates, and restoring your work.

Step 1: Add the Upstream Remote (One-time setup)

To pull updates from the original source repository, you need to configure a remote called upstream that points to the original parent repository on GitHub.

# Add the original repository as 'upstream'
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPO.git

Verify your remotes are set up correctly:

git remote -v
# Output should show 'origin' (your fork) and 'upstream' (the original source)


Step 2: Fetch Remote Metadata & Switch Branch

Fetch all branches from both your fork (origin) and the source (upstream) to make sure your local cache is updated:

# Fetch latest commits from all remotes
git fetch --all

Check out your local main branch (e.g. master or main):

# Switch to the main branch
git checkout master


Step 3: Stash Local Modifications (Safety First)

If you have uncommitted changes in your workspace (such as local configuration files, environment tweaks, or debug profiles), merging changes might cause conflicts.

Save them safely to Git's stash memory:

# Temporarily stash local changes
git stash

This clears your working directory so you can perform the sync smoothly.


Step 4: Pull and Sync from Upstream

Sync your local main branch with the upstream source's main branch:

# Pull upstream changes into your current local branch
git pull upstream master

If your local branch was already up-to-date with upstream, Git will output Already up to date. If there are new commits, they will be cleanly integrated.


Step 5: Restore Your Local Modifications

Bring back the local work you stashed in Step 3:

# Apply and delete the latest stashed state
git stash pop

Git will merge your local changes back into the workspace. If there are minor file conflicts, you can resolve them manually.


Quick Reference: Commands Used

Command Purpose
git remote add upstream <url> Configures the original parent repository as a remote
git fetch --all Downloads references and objects from all remotes
git checkout master Switches active workspace focus to the main branch
git stash Saves dirty workspace state to a stack for later restoration
git pull upstream master Fetches and merges upstream main branch into local
git stash pop Pops and reapplies stashed changes to active workspace