Courses/Git/Working with Remote Repositories

    Lesson 4 • Intermediate

    Working with Remote Repositories 🌿

    Push code to GitHub, pull teammates' changes, create pull requests, and contribute to open source — the collaboration skills every developer needs.

    What You'll Learn in This Lesson

    • • What remotes are and how origin works
    • git push, git pull, and git fetch
    • • Pull requests and code review workflows
    • • Forking and contributing to open source
    • • Keeping your fork synced with upstream

    1️⃣ Remote Basics

    A remote is a version of your repository hosted on a server (GitHub, GitLab, Bitbucket). The default remote created by git clone is called origin. You can have multiple remotes pointing to different servers.

    Try It: Remote Basics

    View, add, and understand remote connections

    Try it Yourself »
    JavaScript
    // Remote Repositories — Collaborate with Others
    console.log("=== What Are Remotes? ===");
    console.log("A remote is a copy of your repository on a server.");
    console.log("GitHub, GitLab, and Bitbucket host remotes.");
    console.log("The default remote is called 'origin'.");
    console.log();
    
    console.log("=== Viewing Remotes ===");
    console.log("  $ git remote -v");
    console.log("  origin  https://github.com/you/project.git (fetch)");
    console.log("  origin  https://github.com/you/project.git (push)");
    
    ...

    2️⃣ Push, Pull, and Fetch

    git push uploads your commits. git pull downloads and merges. git fetch downloads without merging — useful when you want to inspect changes before integrating them.

    Try It: Push & Pull

    Sync your local and remote repositories

    Try it Yourself »
    JavaScript
    // git push & git pull — Syncing with Remote
    console.log("=== git push — Upload Your Work ===");
    console.log();
    console.log("  $ git push origin main");
    console.log("  → Uploads your main branch commits to origin (GitHub)");
    console.log();
    console.log("  First push of a new branch:");
    console.log("  $ git push -u origin feature-login");
    console.log("  → '-u' sets upstream tracking (git push works alone next time)");
    console.log();
    
    console.log("=== git pull — Download & Merge ===");
    console.log(
    ...

    3️⃣ Pull Requests

    Pull requests are the standard way to propose changes on GitHub. They enable code review, discussion, and automated testing before changes are merged into the main branch.

    Try It: Pull Requests

    The complete PR workflow from branch to merge

    Try it Yourself »
    JavaScript
    // Pull Requests — Code Review Workflow
    console.log("=== What is a Pull Request (PR)? ===");
    console.log("A PR is a REQUEST to merge your branch into another branch.");
    console.log("It's where code review, discussion, and CI/CD happen.");
    console.log("(Called 'Merge Request' on GitLab)");
    console.log();
    
    console.log("=== PR Workflow ===");
    const prSteps = [
      "Create a feature branch",
      "Make commits on that branch",
      "Push branch to GitHub",
      "Open a Pull Request (PR) on GitHub",
      "Team rev
    ...

    4️⃣ Forking & Open Source

    Forking creates your own copy of someone else's repository. It's how you contribute to open source — fork, clone, branch, commit, push, then open a PR back to the original project.

    Try It: Forking

    Contribute to open source with forks and upstream remotes

    Try it Yourself »
    JavaScript
    // Forking & Contributing to Open Source
    console.log("=== Forking — Your Copy of Someone Else's Repo ===");
    console.log();
    console.log("A fork is a personal copy of another user's repository.");
    console.log("You can freely experiment without affecting the original.");
    console.log();
    
    console.log("=== Open Source Contribution Workflow ===");
    const forkSteps = [
      { step: "Fork the repository on GitHub", cmd: "(Click 'Fork' button)" },
      { step: "Clone YOUR fork", cmd: "git clone https://github.co
    ...

    ⚠️ Common Mistakes

    ⚠️
    Pushing to main directly — Always use feature branches and pull requests. Direct pushes bypass code review.
    ⚠️
    Forgetting to pull before push — If the remote has new commits, push will be rejected. Pull first, resolve conflicts, then push.
    💡
    Pro Tip: Use git pull --rebase instead of git pull to keep a cleaner history when pulling remote changes.

    📋 Quick Reference

    CommandPurpose
    git remote -vList remotes
    git push origin mainUpload commits
    git pull origin mainDownload & merge
    git fetch originDownload only
    git push -u origin branchFirst push + tracking
    git remote add name URLAdd new remote

    🎉 Lesson Complete!

    You can now push, pull, and collaborate with remote repositories! Next, we'll tackle the most feared Git topic — resolving merge conflicts.

    Sign up for free to track which lessons you've completed and get learning reminders.

    Previous

    Cookie & Privacy Settings

    We use cookies to improve your experience, analyze traffic, and show personalized ads. You can manage your preferences below.

    By clicking "Accept All", you consent to our use of cookies for analytics and personalized advertising. You can customize your preferences or reject non-essential cookies.

    Privacy PolicyTerms of Service