Skip to main content

Collaborate on a Project with Git

Level: Intermediate · Time: 40–50 min · Category: Version control

Tags: Git · Branches · Pull requests · Collaboration

Work on a shared project the way research teams do: clone a repository, do your work on a feature branch, keep it up to date with the main branch, open a pull request for review, and resolve a merge conflict. Use AI coding assistance to explain branch state and help untangle conflicts.

This tutorial builds on Track a New Project with Git. You should be comfortable with add, commit, and push before starting.

Prerequisites

  • Track a New Project with Git — the single-user basics this tutorial assumes.
  • LLM API Guide — set up AI coding assistance to explain branch state and conflict markers.
  • VS Code (recommended) — built-in Git plus the free GitHub Pull Requests extension for reviews without leaving the editor.
  • A shared repository — a GitHub or GitLab repository you can clone and push branches to (your own test repo is fine).

What you will do

  • Clone a shared repository and inspect its branches.
  • Create a focused feature branch for your work.
  • Keep your branch up to date with main.
  • Open a pull request and respond to review.
  • Resolve a merge conflict without losing work.
  • Merge and clean up your branch.

Build it step by step

Prefer a graphical workflow?

Everything here works from VS Code's built-in Git plus the free GitHub Pull Requests extension. Open the Source Control panel (Ctrl+Shift+G / Cmd+Shift+G) to branch, commit, and sync, and use the branch name in the bottom-left status bar to see and switch branches. Each step shows the command line first, followed by the In VS Code equivalent.

1. Clone the shared repository

Cloning downloads the full history and sets up a remote named origin automatically.

git clone https://github.com/your-org/shared-project.git
cd shared-project
git branch -a # list local and remote branches
git log --oneline -5
  • Never commit directly to main on a shared project. Do your work on a branch and merge through review.
In VS Code

Open the Command Palette (Ctrl+Shift+P / Cmd+Shift+P), run Git: Clone, paste the repository URL, and choose a folder. VS Code offers to open the cloned project automatically.

2. Create a feature branch

A branch is an isolated line of work. Name it for the change so teammates understand its purpose.

git switch -c feature/add-results-summary

git switch -c creates the branch and moves to it. Small, well-named branches are much easier to review than large ones.

In VS Code

Click the branch name in the bottom-left status bar (or run Git: Create Branch from the Command Palette), choose Create new branch, and type feature/add-results-summary. The status bar updates to show your new branch.

3. Commit focused changes

Make one logical change per commit. Small commits make review and conflict resolution far easier.

git add <files>
git commit -m "Add results summary section"
git push -u origin feature/add-results-summary
Ask your AI assistant:

Here is `git diff --staged`. Is this one logical change, or should it be split
into separate commits? Suggest commit messages for each.
In VS Code

Stage and commit in the Source Control panel as before, then click Publish Branch to push the new branch to origin. Later commits go up with the Sync Changes button.

4. Keep your branch up to date

While you work, main may move ahead. Integrate those updates regularly so the final merge is small.

git switch main
git pull
git switch feature/add-results-summary
git merge main # or: git rebase main
  • Use merge when you want a simple, safe history. Use rebase for a linear history — but never rebase branches other people already pulled.
In VS Code

Use Sync Changes (or Git: Pull) to update main, switch back to your branch from the status bar, then run Git: Merge Branch and pick main.

5. Open a pull request

A pull request (PR) — called a merge request on GitLab — asks teammates to review your branch before it joins main.

  • Push your branch (step 3), then open the PR in the web UI.
  • Write a short description: what changed, why, and how to test it.
  • Respond to review comments with new commits on the same branch; the PR updates automatically.
Ask your AI assistant:

Draft a pull request description for this branch. Summarize the change, the
reason, and a short "How to test" checklist based on this diff.
In VS Code

Install the GitHub Pull Requests extension. After you publish your branch, it shows a Create Pull Request button, where you can write the description, request reviewers, and read review comments without leaving the editor.

6. Resolve a merge conflict

A conflict happens when two branches change the same lines. Git pauses and marks the conflict so you can choose the correct result.

git merge main
# CONFLICT (content): Merge conflict in report.md

Open the file and find the conflict markers:

<<<<<<< HEAD
your branch's version
=======
main's version
>>>>>>> main

Edit the file to the correct final content, remove all markers, then finish the merge:

git add report.md
git commit # completes the merge

Ask the assistant to explain both sides of a conflict before you delete anything — it can clarify which change to keep or how to combine them.

In VS Code

Conflicted files appear under Merge Changes in Source Control. Click one to open the Merge Editor, which shows Current, Incoming, and Result panes with Accept Current, Accept Incoming, and Accept Both buttons. Resolve every conflict, then click Complete Merge.

7. Merge and clean up

Once the PR is approved and merged in the web UI, update your local main and delete the finished branch.

git switch main
git pull
git branch -d feature/add-results-summary
git push origin --delete feature/add-results-summary

Your change is now part of main, and the branch is cleaned up for the next piece of work.

In VS Code

After the PR merges, run Git: Pull to update main, then Git: Delete Branch from the Command Palette to remove the finished feature branch locally.

More prompts to try

  • Explain the difference between git merge and git rebase, and when each is safe on a shared branch.
  • Walk me through git switch, git restore, and git reset with a safe example of each.
  • I have local changes but need to switch branches quickly. Explain git stash and how to get my changes back.

Troubleshooting

  • If git push is rejected as non-fast-forward, run git pull (or git merge main), resolve conflicts, then push again.
  • If you committed to main by accident, ask the assistant how to move those commits onto a branch with git switch -c and git reset.
  • If a merge goes wrong before you commit it, git merge --abort returns you to the pre-merge state.
  • If you lose track of where you are, git status and git log --oneline --graph --all show your branches and history.

Next steps