Team Git Workflow

Team Git Workflow: Forks, Branches, and Pull Requests



Collaborating on a coding project with a team can be tricky. To prevent conflicts, ensure proper review, and maintain clean code, it’s important to follow a structured Git workflow. Here’s a complete step-by-step guide for team members and team leaders.

1. Initial Setup

Team Leader

  • Create a GitHub repository for the project (e.g., birthday-surprise).
  • Share the repository URL with your team.
  • Optionally, set branch protection rules to ensure main branch can only be updated via Pull Requests.

Team Members

  • Fork the repository to your own GitHub account.
  • Clone your fork locally:
git clone https://github.com/YourUsername/birthday-surprise.git
cd birthday-surprise
  • Add the original repository as upstream:
git remote add upstream https://github.com/Pritom-360/birthday-surprise.git
git remote -v

2. Branch Workflow (Team Members)

  • Sync your fork before starting work:
git fetch upstream
git checkout main
git merge upstream/main
git push origin main
  • Create a new branch for your task:
git checkout -b feature-login
  • Work on your assigned code segment in this branch.

3. Commit and Push Changes

  • Check the status of your changes:
git status
  • Stage your changes:
git add .
  • Commit with a meaningful message:
git commit -m "Added login validation feature"
  • Push your branch to your fork:
git push origin feature-login

4. Create Pull Request (PR)

  • Go to your fork on GitHub.
  • Click Compare & pull request.
  • Set the base repo as the main project repository and base branch as main.
  • Submit the PR with a descriptive title and notes.

5. Team Leader Workflow

  • Open the Pull Request on GitHub.
  • Review the code for correctness and clarity.
  • Approve & Merge if ready, or request changes if revisions are needed.
  • After merging, notify the team to sync their local repositories.

6. Keep Your Branch Up-to-Date

git checkout main
git fetch upstream
git merge upstream/main
git push origin main
git checkout feature-branch
git merge main

7. Best Practices

Team Members

  • Work in feature branches only.
  • Commit small, clear changes.
  • Pull the latest changes before starting work.

Team Leader

  • Review PRs carefully before merging.
  • Encourage descriptive commit messages.
  • Maintain main branch stability.

Following this workflow ensures clean collaboration, prevents code overwrites, and allows the team leader to review and approve changes safely.

Comments