# Git Workflow for Contributing

> Describe the Git workflow you use when contributing to an open-source project. How do you keep your fork in sync and handle merge conflicts?

Canonical: https://www.internhack.in/learn/interview/open-source-interview/oss-git-workflow
Last updated: 2026-11-28

Difficulty: Intermediate

## Question

Describe the Git workflow you use when contributing to an open-source project. How do you keep your fork in sync and handle merge conflicts?

## Answer

A disciplined Git workflow is essential for smooth contributions, especially when working across multiple PRs or with active upstream repositories.

Start by forking the upstream repository and cloning your fork. Add the upstream repository as a remote (git remote add upstream URL). Before starting any work, sync your main branch: git checkout main, git fetch upstream, git merge upstream/main (or rebase).

Create a feature branch from the latest main: git checkout -b fix/issue-description. Make small, atomic commits with clear messages. I use Conventional Commits format (feat:, fix:, chore:, docs:, refactor:).

When the upstream main has moved forward while you're working, rebase your branch: git fetch upstream, git rebase upstream/main. This keeps your commits on top of the latest changes. If conflicts arise, resolve them carefully, testing after each resolution.

Before opening a PR, squash related commits into logical units using git rebase -i. Force push to your branch (git push --force-with-lease). Open the PR against the upstream repository.

During review, make additional commits for requested changes. After the PR is approved, the maintainers may squash-merge, so don't squash prematurely.

## Key points

- Never commit directly to main — always use feature branches
- Use rebase (not merge) to incorporate upstream changes into your branch
- Use --force-with-lease instead of --force for safety
- Keep PRs focused — one logical change per PR

## Common follow-up questions

- What's the difference between rebase and merge, and when would you use each?
- How do you recover from a rebase gone wrong?
- What is the git reflog and when have you used it?

## Interview tips

- Show you understand both the mechanics and the rationale behind each step
- Mention --force-with-lease specifically — it shows you care about safety
- Demonstrate that you can recover from mistakes (reflog, ORIG_HEAD)

## Concepts covered

Git, Rebase, Merge, Squash, Sync, Fork

Previous: [Writing a Good First-Time Issue Comment](https://www.internhack.in/learn/interview/open-source-interview/oss-good-first-issue) · Next: [Handling a Rejected PR](https://www.internhack.in/learn/interview/open-source-interview/oss-rejected-pr) · [All of Open Source Contribution](https://www.internhack.in/learn/interview/open-source-interview)

## More Open Source Contribution questions

- [Fork vs Branch](https://www.internhack.in/learn/interview/open-source-interview/oss-fork-vs-branch)
- [Finding Good First Issues](https://www.internhack.in/learn/interview/open-source-interview/oss-find-good-issues)
- [What Makes a Good PR Description?](https://www.internhack.in/learn/interview/open-source-interview/oss-good-pr-description)
- [Why Open Source?](https://www.internhack.in/learn/interview/open-source-interview/oss-open-source-mindset)
- [Walk Me Through Your Contribution Process](https://www.internhack.in/learn/interview/open-source-interview/oss-contribution-process)
- [Reading an Unfamiliar Codebase](https://www.internhack.in/learn/interview/open-source-interview/oss-read-unfamiliar-codebase)

## Related

- [Learn](https://www.internhack.in/learn)
- [Interview Prep](https://www.internhack.in/learn/interview)
- [Open Source Contribution](https://www.internhack.in/learn/interview/open-source-interview)
