Skip to content

Remote Collaboration Simulation

Medium ~25 min

What you'll build

A bare remote repository and two local clones representing two developers. You will push from one, pull from the other, and handle a rejected push scenario.

Goals

  • Create a bare remote repository
  • Clone, push, and pull between local and remote
  • Simulate two developers collaborating
  • Handle a rejected push by pulling first

Prerequisites

  • git init, clone, commit, push, pull

Steps

  1. 1

    Create a bare remote repository

    A bare repository has no working directory — it is meant to be pushed to and pulled from, like a GitHub repo. Create one to act as the 'server'.

    Code
    mkdir remote-sim
    cd remote-sim
    git init --bare shared.git

    Expected result

    A bare repository at shared.git that can serve as a remote.

  2. 2

    Developer 1 clones and pushes initial work

    Clone the bare repo as developer 1, add a file, commit, and push. This simulates the first developer setting up the project.

    Code
    git clone shared.git dev1
    cd dev1
    echo "# Shared Project" > README.md
    git add .
    git commit -m "Initial commit"
    git push origin main

    Expected result

    dev1 has pushed the initial commit to the shared remote.

  3. 3

    Developer 2 clones and makes changes

    Clone the same remote as developer 2. This simulates a second team member joining the project. Make a change, commit, and push.

    Code
    cd ../
    git clone shared.git dev2
    cd dev2
    echo "console.log('hello')" > app.js
    git add .
    git commit -m "Add hello script"
    git push origin main

    Expected result

    dev2 has added and pushed a new file to the remote.

  4. 4

    Developer 1 pulls the latest changes

    Back in dev1, pull the changes that dev2 pushed. This is how collaborators stay in sync — pull before you start working.

    Code
    cd ../dev1
    git pull origin main
    ls  # should show app.js now

    Expected result

    dev1 now has app.js from dev2's push.

  5. 5

    Handle a rejected push

    Simulate a rejected push: both developers commit simultaneously. dev1's push is rejected because the remote has dev2's new commit. Pull first, then push.

    Code
    # dev2 makes a change
    cd ../dev2
    echo "v2" > version.txt
    git add .
    git commit -m "Add version file"
    git push origin main
    
    # dev1 also makes a change and tries to push
    cd ../dev1
    echo "config" > settings.txt
    git add .
    git commit -m "Add settings"
    git push origin main  # REJECTED!
    
    # Fix: pull first, then push
    git pull --rebase origin main
    git push origin main  # succeeds

    Expected result

    After pulling and rebasing, dev1's push succeeds.

Try it yourself

What you learned

You simulated a full remote collaboration: bare repo, two clones, push/pull sync, and a rejected push resolved with pull --rebase. This is the daily workflow of every team using Git.

Related Resources

Related Lessons

Related Cheatsheets

Look up unfamiliar terms

A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.

View glossary

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to topic