Chapter 18: Git Hosting Platforms and Collaboration

Chapter Objectives

By the end of this chapter, you will be able to:

  • Understand the role and importance of Git hosting platforms in modern software development.
  • Identify key features of popular platforms like GitHub, GitLab, and Bitbucket.
  • Describe the concept and lifecycle of Pull Requests (PRs) and Merge Requests (MRs).
  • Outline the typical process for creating, reviewing, and merging PRs/MRs.
  • Appreciate best practices for effective collaboration using these platforms.
  • Recognize how hosting platforms facilitate different Git workflows.

Introduction

Throughout this book, you’ve learned how Git provides a powerful distributed version control system for managing your code locally and interacting with remote repositories. While Git itself is a command-line tool, its true potential for collaboration is unlocked when paired with Git hosting platforms. These platforms provide a central place for teams and communities to store their repositories, manage projects, review code, track issues, and automate workflows.

Services like GitHub, GitLab, and Bitbucket have become integral to the software development lifecycle. They build upon Git’s core functionality by offering web-based interfaces and a suite of tools designed to streamline collaboration, enhance code quality, and manage the complexities of developing software, whether for a small team or a global open-source project.

In this chapter, we’ll explore these popular Git hosting platforms, highlighting their common features and unique strengths. We will delve deep into the concept of Pull Requests (or Merge Requests), which are the cornerstone of collaborative coding on these platforms. Finally, we’ll discuss best practices for working effectively with others in this environment, ensuring that your team can leverage these tools to their fullest potential.

Theory

What are Git Hosting Platforms?

Git hosting platforms are web-based services that provide hosting for Git repositories. Think of them as specialized hubs for your Git projects. While you can set up your own private Git server, these platforms offer much more than just remote storage. They provide a rich ecosystem of tools and features built around Git to facilitate software development and collaboration.

Key Roles of Hosting Platforms:

  • Centralized Remote Repositories: They offer a canonical place to store your project’s codebase, accessible to authorized team members or the public.
  • Collaboration Hub: They act as a central point for team communication, code reviews, and project management.
  • Enhanced Git Functionality: They provide user-friendly web interfaces for tasks that can be complex on the command line, such as browsing history, comparing branches, and managing access.
  • Integration with Development Lifecycle: Many platforms integrate with various stages of the software development lifecycle, including issue tracking, continuous integration/continuous deployment (CI/CD), and project planning.

Overview of Popular Platforms

While many Git hosting services exist, three major players dominate the landscape: GitHub, GitLab, and Bitbucket. Each has its unique offerings, but they share a core set of features.

Common Features Across Platforms:

  • Repositories: Hosting for public and private Git repositories.
  • Issue Trackers: Systems for reporting bugs, requesting features, and managing tasks.
  • Pull Requests (PRs) / Merge Requests (MRs): Mechanisms for proposing changes, conducting code reviews, and merging code. (GitHub and Bitbucket use “Pull Request”; GitLab uses “Merge Request” – the concept is the same).
  • Wikis: For project documentation.
  • Code Review Tools: Inline commenting, diff views, approval workflows.
  • CI/CD Integration: Built-in or tightly integrated tools for automating builds, tests, and deployments (e.g., GitHub Actions, GitLab CI/CD, Bitbucket Pipelines).
  • Access Control: Granular permissions for repository access and collaboration.
  • Project Management Tools: Features like Kanban boards, milestones, and roadmaps.
  • Branching and Merging Visualizations: Web UI to see branch history and relationships.

1. GitHub:

  • Overview: Launched in 2008, GitHub is arguably the most popular Git hosting platform, especially for open-source projects. It was acquired by Microsoft in 2018.
  • Key Strengths:
    • Vast open-source community and social coding features (following users/projects, stars, forks).
    • GitHub Actions: Powerful and flexible CI/CD and workflow automation tool integrated directly into repositories.
    • GitHub Pages: Simple hosting for static websites directly from a repository.
    • Excellent user interface and developer experience.
    • Strong focus on community and collaboration tools.
    • Marketplace for integrating third-party applications.

2. GitLab:

  • Overview: Launched in 2011, GitLab positions itself as a complete DevOps platform delivered as a single application.
  • Key Strengths:
    • All-in-one DevOps: Tightly integrated features spanning the entire software development lifecycle, from planning and SCM to CI/CD, monitoring, and security.
    • Self-Hosting Option: GitLab offers a Community Edition that can be self-hosted, giving organizations full control over their infrastructure. They also offer a SaaS (cloud-hosted) version.
    • Powerful CI/CD: GitLab CI/CD is known for its robustness and ease of use, with configuration managed via a .gitlab-ci.yml file in the repository.
    • Built-in container registry, Kubernetes integration, and advanced security scanning features.

3. Bitbucket:

  • Overview: Developed by Atlassian, Bitbucket is a popular choice, especially for teams already using other Atlassian products like Jira (issue tracking) and Trello (project management).
  • Key Strengths:
    • Atlassian Suite Integration: Seamless integration with Jira, Trello, Confluence, and other Atlassian tools.
    • Historically offered free private repositories for small teams before GitHub did, making it popular for closed-source projects.
    • Bitbucket Pipelines: Integrated CI/CD service.
    • Good support for Git Large File Storage (LFS).
    • Previously supported Mercurial repositories, though now primarily focuses on Git.
Feature / Aspect GitHub GitLab Bitbucket (Atlassian)
Primary Focus / Strength Open-source community, social coding, developer experience, GitHub Actions. Complete DevOps platform (single application), powerful integrated CI/CD, self-hosting option. Integration with Atlassian suite (Jira, Trello, Confluence), popular for enterprise teams.
Open Source Community Largest, very strong focus. Growing, strong support for open source. Supports open source, but historically stronger for private/enterprise projects.
Self-Hosting Option GitHub Enterprise Server (Paid). GitLab Community Edition (Free), GitLab Enterprise Edition (Paid). Bitbucket Data Center (Paid).
CI/CD Solution GitHub Actions (Integrated, flexible). GitLab CI/CD (Integrated, powerful, configured via .gitlab-ci.yml). Bitbucket Pipelines (Integrated).
Issue Tracking GitHub Issues (Integrated, good for most projects). GitLab Issues (Integrated, feature-rich, includes boards, epics). Bitbucket Issues (Integrated), deep integration with Jira (often preferred for advanced needs).
Pull/Merge Requests Pull Requests. Merge Requests. Pull Requests.
Free Private Repositories Yes, with feature limitations on free tier (e.g., for Actions minutes, storage). Yes, with feature limitations on free tier. Yes, for small teams (up to 5 users on free plan).
Static Site Hosting GitHub Pages. GitLab Pages. Possible via Pipelines or third-party integrations.
Container Registry GitHub Packages (includes container registry). Integrated Container Registry. Integrates with Docker Hub, Atlassian’s own registry options.
Unique Selling Points
  • Massive community & network effect.
  • GitHub Copilot (AI pair programmer).
  • Extensive Marketplace.
  • Single application for the entire DevOps lifecycle.
  • Mature and robust self-hosting capabilities.
  • Advanced security features integrated (SAST, DAST).
  • Best-in-class integration with Jira and other Atlassian tools.
  • Strong support for Git LFS.
  • Good for teams already invested in the Atlassian ecosystem.

Pull Requests (PRs) / Merge Requests (MRs): The Core of Collaboration

Pull Requests (on GitHub/Bitbucket) or Merge Requests (on GitLab) are the heart of collaborative development on these platforms. A PR/MR is a formal proposal to merge a set of changes from one branch into another. This process allows for code review, discussion, and automated checks before the changes are integrated into the main codebase.

Purpose of PRs/MRs:

  • Code Review: Allows team members to review code for quality, correctness, style, and potential issues.
  • Discussion: Provides a forum for discussing the proposed changes, asking questions, and offering suggestions.
  • Controlled Integration: Ensures that changes are only merged after they meet certain criteria (e.g., review approval, passing tests).
  • Automated Checks: CI systems can automatically run tests, linters, and other checks on the changes in a PR/MR.
  • Historical Record: Serves as a record of why a change was made, who reviewed it, and any related discussions.

Typical Lifecycle of a PR/MR:

  1. Branch Creation and Development:
    • A developer creates a new branch (feature branch, bugfix branch) locally, typically from the main development branch (e.g., main or develop).
    • The developer makes commits to this branch.
    • The developer pushes this branch to the remote repository (their fork or the shared project repository).
    git checkout -b feature/new-login-page main # ... make commits ... git push -u origin feature/new-login-page
  2. Opening the PR/MR:
    • The developer navigates to the Git hosting platform (GitHub, GitLab, Bitbucket).
    • They initiate a new PR/MR, selecting their feature branch as the source and the target branch (e.g., main or develop) for the merge.
    • They provide a descriptive title and a detailed description of the changes, often referencing related issues.
  3. Code Review and Discussion:
    • Team members (reviewers) are notified or assigned to the PR/MR.
    • Reviewers examine the code changes (the “diff”), add inline comments, ask questions, and suggest improvements.
    • A discussion ensues within the PR/MR interface.
  4. Automated Checks (CI):
    • If CI/CD is configured, automated builds, tests, and code analysis tools run against the changes in the PR/MR.
    • The status of these checks (pass/fail) is displayed on the PR/MR page.
  5. Iteration and Updates:
    • Based on review feedback and CI results, the original developer makes further commits to their feature branch locally.
    • They push these new commits to the same remote branch. The PR/MR on the platform automatically updates to reflect these new changes.
    • This cycle of review, feedback, and updates continues until the changes are satisfactory.
  6. Approval and Merging:
    • Once reviewers approve the changes and all checks pass, a designated maintainer (or the developer if permissions allow) merges the PR/MR.
    • Platforms often offer different merge strategies (e.g., create a merge commit, squash and merge, rebase and merge).
    • The merge is typically performed via the platform’s web UI.
  7. Closing and Branch Deletion:
    • After merging, the PR/MR is closed.
    • It’s common practice to delete the feature branch (both on the remote and locally) to keep the repository tidy. Platforms often offer a button to delete the source branch after merging.
    # After PR is merged and closed via web UI git checkout main git pull origin main # Update local main git branch -d feature/new-login-page # Delete local branch # git push origin --delete feature/new-login-page # If not deleted via UI
%%{ init: { "theme": "base", "themeVariables": {
  "primaryColor": "#EDE9FE", "primaryTextColor": "#5B21B6", "primaryBorderColor": "#5B21B6", /* Start/End points */
  "lineColor": "#5B21B6", "textColor": "#1F2937",
  "mainBkg": "#DBEAFE", "nodeBorder": "#2563EB", "nodeTextColor": "#1E40AF", /* Process Nodes */
  "secondaryColor": "#D1FAE5", "secondaryBorderColor": "#059669", "secondaryTextColor": "#065F46", /* Success/Merge Node */
  "tertiaryColor": "#FEF3C7", "tertiaryBorderColor": "#D97706", "tertiaryTextColor": "#92400E", /* Decision/Review Nodes */
  "errorColor": "#FEE2E2", "errorBorderColor": "#DC2626", "errorTextColor": "#991B1B" /* Check/Validation Nodes */
} } }%%
graph TD
    A["<b>1. Branch & Develop</b><br>Developer creates feature branch locally<br>(e.g., feature/X from main/develop)<br>Commits changes"] --> B{"<b>2. Push Branch</b><br>Developer pushes feature branch<br>to remote repository<br><i>git push -u origin feature/X</i>"}
    style A fill:#DBEAFE,stroke:#2563EB,stroke-width:1px,color:#1E40AF
    style B fill:#DBEAFE,stroke:#2563EB,stroke-width:1px,color:#1E40AF

    B --> C["<b>3. Open PR/MR</b><br>On hosting platform (GitHub, GitLab, etc.)<br>Source: feature/X, Target: main/develop<br>Add title, description, reviewers"]
    style C fill:#DBEAFE,stroke:#2563EB,stroke-width:1px,color:#1E40AF

    C --> D{"<b>4. Automated Checks (CI)</b><br>CI server runs tests, linters, builds<br>Status reported on PR/MR"}
    style D fill:#FEE2E2,stroke:#DC2626,stroke-width:1px,color:#991B1B

    D -- "Checks Pass" --> E["<b>5. Code Review & Discussion</b><br>Team members review code, add comments<br>Discuss changes, suggest improvements"]
    style E fill:#FEF3C7,stroke:#D97706,stroke-width:1px,color:#92400E
    
    D -- "Checks Fail" --> F["<b>6. Iterate & Update</b><br>Developer makes fixes locally<br>Commits and pushes to feature/X<br>PR/MR updates automatically"]
    style F fill:#DBEAFE,stroke:#2563EB,stroke-width:1px,color:#1E40AF
    F --> D

    E -- "Changes Requested" --> F
    E -- "Approved" --> G["<b>7. Merge PR/MR</b><br>Maintainer merges feature/X into target branch<br>(via platform UI - merge, squash, or rebase)"]
    style G fill:#D1FAE5,stroke:#059669,stroke-width:2px,color:#065F46

    G --> H["<b>8. Close PR/MR & Delete Branch</b><br>PR/MR is closed automatically<br>Feature branch often deleted on remote & locally"]
    style H fill:#DBEAFE,stroke:#2563EB,stroke-width:1px,color:#1E40AF
    
    H --> I["<b>End: Target Branch Updated</b><br>main/develop now contains new feature/fix"]
    style I fill:#EDE9FE,stroke:#5B21B6,stroke-width:2px,color:#5B21B6

    linkStyle default interpolate basis

Collaboration Best Practices on Hosting Platforms

Effective collaboration relies not just on tools but also on good practices:

  • Clear Communication:
    • Write clear, concise commit messages.
    • Provide detailed descriptions for PRs/MRs, explaining the “what” and “why” of the changes. Reference related issues (e.g., “Fixes #123”).
    • Participate actively and respectfully in discussions within issues and PRs/MRs.
  • Atomic Changes:
    • Keep commits small and focused on a single logical change.
    • Aim for PRs/MRs that address one specific feature or bug. Large PRs are difficult and time-consuming to review.
  • Follow Contribution Guidelines:
    • Many projects have a CONTRIBUTING.md file outlining coding standards, testing requirements, and the expected PR/MR process. Read and follow it.
  • Use Issue Trackers Effectively:
    • Report bugs with clear, reproducible steps.
    • Use labels, milestones, and assignees to organize and prioritize work.
    • Link PRs/MRs to the issues they address.
  • Constructive Code Reviews:
    • For Reviewers: Be thorough but constructive. Focus on the code, not the person. Explain your reasoning. Offer suggestions, not just criticisms.
    • For Authors: Be open to feedback. Understand that reviews are meant to improve code quality. Ask for clarification if needed.
  • Keep Branches Up-to-Date:
    • Before opening a PR/MR, or during a long review process, rebase your feature branch onto the latest target branch (e.g., main or develop) to incorporate recent changes and resolve potential conflicts early.
  • Leverage Platform Features:
    • Use features like draft PRs/MRs for work in progress.
    • Utilize code owners, required status checks, and branch protection rules to enforce quality and process.

Practical Examples (Conceptual)

Please follow platforms’ examples for better understanding of platforms.

GitHub PR Workflow:

%%{ init: { "theme": "base", "themeVariables": {
  "primaryColor": "#EDE9FE", "primaryTextColor": "#5B21B6", "primaryBorderColor": "#5B21B6", /* Upstream Repo */
  "lineColor": "#5B21B6", "textColor": "#1F2937",
  "mainBkg": "#DBEAFE", "nodeBorder": "#2563EB", "nodeTextColor": "#1E40AF", /* Process/Local Repo Node */
  "secondaryColor": "#D1FAE5", "secondaryBorderColor": "#059669", "secondaryTextColor": "#065F46", /* Success/Merge Node */
  "tertiaryColor": "#FEF3C7", "tertiaryBorderColor": "#D97706", "tertiaryTextColor": "#92400E", /* PR/Fork Repo Node */
  "errorColor": "#FEE2E2", "errorBorderColor": "#DC2626", "errorTextColor": "#991B1B" /* Action/Decision Node */
} } }%%
graph TD
    subgraph "Original Project (Upstream)"
        direction TB
        UpstreamRepo["<b>Upstream Repo</b><br>(original-owner/project)<br>Target Branch (e.g., main)"]
        style UpstreamRepo fill:#EDE9FE,stroke:#5B21B6,stroke-width:2px,color:#5B21B6
    end

    subgraph "Contributor's Environment"
        direction TB
        ForkAction["1- Fork Upstream Repo"] --> UserFork["<b>Your Fork on GitHub</b><br>(your-username/project)"]
        style ForkAction fill:#FEE2E2,stroke:#DC2626,stroke-width:1px,color:#991B1B
        style UserFork fill:#FEF3C7,stroke:#D97706,stroke-width:1px,color:#92400E

        UserFork -- "2- git clone" --> LocalRepo["<b>Local Repository</b><br>Add upstream: <code style='font-family:monospace;background-color:#E5E7EB;padding:1px 3px;border-radius:3px;'>git remote add upstream ...</code>"]
        style LocalRepo fill:#DBEAFE,stroke:#2563EB,stroke-width:1px,color:#1E40AF
        
        LocalRepo -- "3- Sync main with Upstream<br><code style='font-family:monospace;background-color:#E5E7EB;padding:1px 3px;border-radius:3px;'>git fetch upstream</code><br><code style='font-family:monospace;background-color:#E5E7EB;padding:1px 3px;border-radius:3px;'>git merge upstream/main</code>" --> CreateBranch["4- Create Feature Branch<br><code style='font-family:monospace;background-color:#E5E7EB;padding:1px 3px;border-radius:3px;'>git checkout -b my-feature main</code>"]
        style CreateBranch fill:#DBEAFE,stroke:#2563EB,stroke-width:1px,color:#1E40AF
        
        CreateBranch --> Develop["5- Make Changes, Commit Locally"]
        style Develop fill:#DBEAFE,stroke:#2563EB,stroke-width:1px,color:#1E40AF
        
        Develop -- "6- git push -u origin my-feature" --> UserForkFeature["<b>my-feature</b> branch on Your Fork"]
        style UserForkFeature fill:#FEF3C7,stroke:#D97706,stroke-width:1px,color:#92400E
        
        UserForkFeature --> OpenPR["7- Open Pull Request (PR)<br>From: your-username/project (my-feature)<br>To: original-owner/project (main)"]
        style OpenPR fill:#FEE2E2,stroke:#DC2626,stroke-width:1px,color:#991B1B
    end
    
    UpstreamRepo -. Fork .-> ForkAction
    OpenPR -- "8- Review, Discuss, Iterate (Push more commits to my-feature on Fork)" --> ReviewCycle{Review Cycle}
    style ReviewCycle fill:#FEF3C7,stroke:#D97706,stroke-width:1px,color:#92400E
    ReviewCycle -- Feedback --> Develop
    ReviewCycle -- Approved --> MergePR["9- Maintainer Merges PR"]
    style MergePR fill:#D1FAE5,stroke:#059669,stroke-width:2px,color:#065F46
    
    MergePR --> UpstreamRepoUpdated["Upstream Repo Updated<br>with my-feature"]
    style UpstreamRepoUpdated fill:#D1FAE5,stroke:#059669,stroke-width:2px,color:#065F46
    UpstreamRepoUpdated --> Cleanup["10- Clean Up<br>Delete remote & local feature branch<br>Sync local main with upstream"]
    style Cleanup fill:#DBEAFE,stroke:#2563EB,stroke-width:1px,color:#1E40AF
    
    linkStyle default interpolate basis

GitLab MR Workflow:

%%{ init: { "theme": "base", "themeVariables": {
  "primaryColor": "#EDE9FE", "primaryTextColor": "#5B21B6", "primaryBorderColor": "#5B21B6", /* Shared Repo */
  "lineColor": "#5B21B6", "textColor": "#1F2937",
  "mainBkg": "#DBEAFE", "nodeBorder": "#2563EB", "nodeTextColor": "#1E40AF", /* Process/Local Repo Node */
  "secondaryColor": "#D1FAE5", "secondaryBorderColor": "#059669", "secondaryTextColor": "#065F46", /* Success/Merge Node */
  "tertiaryColor": "#FEF3C7", "tertiaryBorderColor": "#D97706", "tertiaryTextColor": "#92400E", /* MR/Review Node */
  "errorColor": "#FEE2E2", "errorBorderColor": "#DC2626", "errorTextColor": "#991B1B" /* Action/Decision Node */
} } }%%
graph TD
    subgraph "Shared GitLab Project Repository (your-team/project)"
        SharedRepo["<b>Shared Project Repo (origin)</b><br>Branches: main, develop"]
        style SharedRepo fill:#EDE9FE,stroke:#5B21B6,stroke-width:2px,color:#5B21B6
    end

    subgraph "Developer's Local Environment"
        CloneRepo["1- Clone Project Repo<br><code style='font-family:monospace;background-color:#E5E7EB;padding:1px 3px;border-radius:3px;'>git clone ...</code>"] --> SyncDev["2- Sync with Remote develop<br><code style='font-family:monospace;background-color:#E5E7EB;padding:1px 3px;border-radius:3px;'>git checkout develop</code><br><code style='font-family:monospace;background-color:#E5E7EB;padding:1px 3px;border-radius:3px;'>git pull origin develop</code>"]
        style CloneRepo fill:#DBEAFE,stroke:#2563EB,stroke-width:1px,color:#1E40AF
        style SyncDev fill:#DBEAFE,stroke:#2563EB,stroke-width:1px,color:#1E40AF

        SyncDev --> CreateBranch["3- Create Feature Branch<br><code style='font-family:monospace;background-color:#E5E7EB;padding:1px 3px;border-radius:3px;'>git checkout -b feature/X develop</code>"]
        style CreateBranch fill:#DBEAFE,stroke:#2563EB,stroke-width:1px,color:#1E40AF
        
        CreateBranch --> DevelopLocally["4- Make Changes, Commit Locally"]
        style DevelopLocally fill:#DBEAFE,stroke:#2563EB,stroke-width:1px,color:#1E40AF
        
        DevelopLocally -- "5- git push -u origin feature/X" --> PushedBranch["<b>feature/X</b> pushed to Shared Repo"]
        style PushedBranch fill:#DBEAFE,stroke:#2563EB,stroke-width:1px,color:#1E40AF
    end
    
    SharedRepo -.-> CloneRepo
    PushedBranch --> OpenMR["6- Open Merge Request (MR) on GitLab<br>Source: feature/X<br>Target: develop (or main)"]
    style OpenMR fill:#FEE2E2,stroke:#DC2626,stroke-width:1px,color:#991B1B
    
    OpenMR --> ReviewCycle["7- CI Runs, Code Review, Discussion, Iterate<br>(Push more commits to feature/X as needed)"]
    style ReviewCycle fill:#FEF3C7,stroke:#D97706,stroke-width:1px,color:#92400E
    ReviewCycle -- Feedback --> DevelopLocally
    
    ReviewCycle -- Approved --> MergeMR["8- Maintainer Merges MR<br>(Often with options: squash, delete source branch)"]
    style MergeMR fill:#D1FAE5,stroke:#059669,stroke-width:2px,color:#065F46
    
    MergeMR --> TargetBranchUpdated["Target Branch (develop/main)<br>in Shared Repo is Updated"]
    style TargetBranchUpdated fill:#D1FAE5,stroke:#059669,stroke-width:2px,color:#065F46

    TargetBranchUpdated --> LocalCleanup["9- Clean Up Locally<br><code style='font-family:monospace;background-color:#E5E7EB;padding:1px 3px;border-radius:3px;'>git checkout develop</code><br><code style='font-family:monospace;background-color:#E5E7EB;padding:1px 3px;border-radius:3px;'>git pull</code><br><code style='font-family:monospace;background-color:#E5E7EB;padding:1px 3px;border-radius:3px;'>git branch -d feature/X</code>"]
    style LocalCleanup fill:#DBEAFE,stroke:#2563EB,stroke-width:1px,color:#1E40AF

    linkStyle default interpolate basis

OS-Specific Notes

Git hosting platforms are web-based services, and the primary interaction with their advanced features (like Pull/Merge Requests, issue tracking, CI/CD dashboards) happens through a web browser. The Git command-line operations used to prepare branches for these platform interactions (git clone, push, pull, branch, commit, etc.) are consistent across Windows, macOS, and Linux.

Therefore, there are no significant OS-specific notes for the core concepts and workflows discussed in this chapter related to the platforms themselves. Any OS-specific considerations would typically relate to local Git client setup or shell environment, which have been covered in previous chapters.

Common Mistakes & Troubleshooting Tips

Issue / Error Symptom(s) Troubleshooting / Solution
PR/MR Targets Wrong Branch Mistake: PR/MR created with incorrect base (target) branch.
Symptom: Diff includes unexpected commits; PR/MR hard to merge or introduces wrong code.
Solution: Most platforms allow editing the target branch of an open PR/MR. If not, close and reopen with correct target. Always double-check source/target branches.
Forgot to Push Branch Before PR/MR Mistake: Local commits made, but branch not pushed before creating PR/MR.
Symptom: Platform can’t find the feature branch for the PR/MR.
Solution: Ensure local feature branch is pushed to the correct remote: git push -u origin <branch-name>.
Large, Monolithic PRs/MRs Mistake: Single PR/MR with too many changes or unrelated features.
Symptom: Long review times, overwhelmed reviewers, higher risk of bugs.
Solution: Break down tasks into smaller, focused PRs/MRs. Aim for changes reviewable in a reasonable time.
Ignoring CI Failures or Review Feedback Mistake: Merging PR/MR despite failing CI checks or unresolved critical review feedback.
Symptom: Bugs in main codebase, technical debt, team frustration.
Solution: Address CI failures and review comments by making changes and pushing updates. Ensure all checks pass and concerns are resolved before merging. Use branch protection rules.
Persistent Merge Conflicts in PR/MR Mistake: Feature branch significantly diverged from target, causing complex conflicts.
Symptom: Platform indicates merge conflicts, prevents merging.
Solution:
  1. Checkout feature branch locally: git checkout feature/my-feature.
  2. Update from target branch: git pull origin main (merges main in) or (often preferred) git fetch origin; git rebase origin/main.
  3. Resolve conflicts locally.
  4. Push updated branch: git push --force-with-lease origin feature/my-feature (if rebased) or git push origin feature/my-feature (if merged).
  5. PR/MR should update and show conflicts resolved.
Accidentally Pushed to Wrong Remote/Branch Mistake: Pushed sensitive data or to an incorrect upstream branch (if permissions allow).
Symptom: Unintended changes in remote, potential security issues.
Solution: If pushed to wrong branch and not yet widely pulled: git push origin --delete <branch-name> then push to correct one. If sensitive data, refer to platform docs for removing data from history (e.g., BFG Repo-Cleaner, git filter-repo) and rotate any exposed credentials. This can be complex. Always verify remotes with git remote -v.

Exercises

  1. GitHub Exploration and Mock Pull Request:
    1. If you don’t have one, create a free account on GitHub.com.
    2. Find a small, simple public repository (or create one of your own and make it public).
    3. Fork this repository to your own GitHub account.
    4. Clone your forked repository to your local machine.
    5. Create a new branch locally (e.g., my-test-edit).
    6. Make a trivial change (e.g., add a comment to a file, or edit a line in a README).
    7. Commit your change locally.
    8. Push your new branch to your forked repository on GitHub (origin).
    9. On GitHub, navigate to your forked repository and initiate a Pull Request from your my-test-edit branch to the main (or default) branch of your own fork (to avoid sending a test PR to an unsuspecting project).
    10. Examine the Pull Request interface: title, description, diff view, commits tab, checks tab (if any).
    11. “Merge” your own Pull Request using the GitHub UI. Choose to delete the source branch after merging.
    12. Pull the changes into your local main branch.
  2. Analyzing Project Collaboration:
    1. Choose a moderately active open-source project on GitHub, GitLab, or Bitbucket.
    2. Navigate to its Issues section. Observe:
      • How are new issues reported? What information is typically included?
      • How are labels, milestones, or assignees used?
      • Look at the discussion on a few closed and open issues.
    3. Navigate to its Pull Requests / Merge Requests section. Observe:
      • Examine a few recently merged PRs/MRs. What kind of information is in the description?
      • Look at the discussion, code review comments, and any CI/CD checks.
      • How long did it take for the PR/MR to be merged? How many commits were involved?
    4. (Optional) If the project has a CONTRIBUTING.md file, read it to understand its specific guidelines for contributions.

Summary

  • Git Hosting Platforms (e.g., GitHub, GitLab, Bitbucket) provide web-based hosting for Git repositories along with a suite of tools for collaboration, issue tracking, code review, and CI/CD.
  • Pull Requests (PRs) / Merge Requests (MRs) are the primary mechanism for proposing, reviewing, discussing, and integrating code changes on these platforms.
  • The typical PR/MR lifecycle involves creating a feature branch, pushing it, opening a PR/MR, undergoing code review and automated checks, iterating on feedback, and finally, merging the approved changes.
  • Collaboration best practices include clear communication, atomic changes, following contribution guidelines, effective use of issue trackers, constructive code reviews, and keeping branches up-to-date.
  • These platforms facilitate various Git workflows, especially the Feature Branch Workflow and the Forking Workflow, by providing the necessary infrastructure for remote repositories, branch management, and controlled code integration.

Leveraging Git hosting platforms effectively is essential for modern software development, enabling teams and communities to collaborate efficiently and build high-quality software.

Further Reading

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top