Back to roadmaps git Course

Project: Team Feature Development and Conflict Resolution

In this project, we will simulate a real-world team collaboration workflow: developing a feature on a separate branch, handling a push rejection caused by remote changes, and resolving the resulting merge conflict.


1. Project Steps

graph TD
    A[Switch to main and pull latest] --> B[Create feature/api branch]
    B --> C[Modify userApi.js and commit]
    C -->|Try to push| D{Push rejected by remote?}
    D -->|Yes| E[Run git pull --rebase]
    E --> F[Resolve conflicts in editor]
    F --> G[Run git rebase --continue and push]

2. Walkthrough Guide

Step 1: Initialize the Scenario

Create a new directory and initialize Git:

mkdir git-collab-demo
cd git-collab-demo
git init
echo "const apiURL = 'https://api.example.com';" > userApi.js
git add .
git commit -m "initial commit"

Step 2: Create a Feature Branch

Create and switch to your feature branch:

git switch -c feature/api

Modify the API URL in userApi.js to point to staging:

// userApi.js
const apiURL = 'https://staging.api.example.com';

Stage and commit your changes:

git add userApi.js
git commit -m "feat: change api endpoint to staging"

Step 3: Simulate a Teammate's Remote Push

To simulate a teammate pushing changes to the remote branch while you were working, switch back to main, modify the file, and commit:

git switch main

Modify userApi.js to point to production:

// userApi.js
const apiURL = 'https://production.api.example.com';

Commit the change to main:

git add userApi.js
git commit -m "feat: use production endpoint on main"

Step 4: Rebase Your Feature Branch

Switch back to your feature branch and rebase it onto main to integrate the updates:

git switch feature/api
git rebase main

This triggers a conflict:

Auto-merging userApi.js
CONFLICT (content): Merge conflict in userApi.js

Step 5: Resolve the Conflict

Open userApi.js in your editor to locate the conflict markers:

<<<<<<< HEAD
const apiURL = 'https://production.api.example.com';
=======
const apiURL = 'https://staging.api.example.com';
>>>>>>> feat: change api endpoint to staging

Resolve the conflict by keeping the staging endpoint, then delete the markers:

const apiURL = 'https://staging.api.example.com';

Stage the resolved file and continue the rebase:

git add userApi.js
git rebase --continue

Your feature branch is now successfully rebased and aligned with the latest changes from main.

Published on Last updated: