Git Collaboration: GitHub Pull Requests, Branching Strategies, Hooks and Protection

DevOps Certification 20 min min read Updated: Nov 17, 2026 Intermediate
Git Collaboration: GitHub Pull Requests, Branching Strategies, Hooks and Protection
Intermediate Topic 3 of 3

Connect to GitHub with SSH

bash ssh-keygen -t ed25519 -C "you@example.com" cat ~/.ssh/id_ed25519.pub # copy this into GitHub: Settings > SSH and GPG keys ssh -T git@github.com # test: "Hi username! You've successfully authenticated" git remote set-url origin git@github.com:me/shop.git

The Pull Request Flow

A pull request (PR), called a *merge request* in GitLab, proposes merging your branch into another branch. It is where review, discussion and automated checks happen.

text 1. Create branch -> 2. Commit & push -> 3. Open PR -> 4. CI runs + reviewers comment 5. Update branch -> 6. Approval + green checks -> 7. Merge -> 8. Delete branch
bash git switch -c fix/health-endpoint # ... edit and commit ... git push -u origin fix/health-endpoint gh pr create --title "Fix health endpoint" --body "Returns 200 when DB is reachable." --base main gh pr checks # see CI status gh pr merge --squash --delete-branch

Forks

For open source you usually fork (copy) the repository to your account, push to your fork and open a PR to the original (called upstream).

bash git remote add upstream https://github.com/original/project.git git fetch upstream git rebase upstream/main git push origin my-branch

A Good Pull Request

  • Small: easier to review, faster to merge
  • Clear title and description: what, why, how you tested
  • Linked issue (Closes #123)
  • Passing automated tests and linters
  • Screenshots or logs when helpful
  • Reviewers: be kind, specific and focus on correctness, security and clarity. Authors: respond to every comment

Branch Protection and CODEOWNERS

Protect main so nobody can break it by accident. In GitHub: Settings, Branches (or Rulesets).

  • Require a pull request and at least one approval
  • Require status checks (build, tests, security scan) to pass
  • Require branches to be up to date and conversations resolved
  • Block force-pushes and deletion
  • Require signed commits or linear history if your team wants
text # .github/CODEOWNERS - automatically request review from owners * @org/platform-team /terraform/ @org/infra-team /k8s/ @org/sre-team *.sql @org/data-team

Branching Strategies

StrategyHow it worksBest for
GitHub Flowmain is always deployable. Short feature branches, PR, merge, deployWeb apps with continuous deployment
Trunk-based developmentEveryone merges small changes to main (trunk) at least daily. Unfinished work hides behind feature flagsHigh-performing teams with strong CI
GitflowLong-lived main and develop, plus feature, release and hotfix branchesVersioned products with scheduled releases
Environment branchesA branch per environment (dev, staging, prod)Often discouraged. Prefer one branch and promote artifacts
Modern guidance: Research on delivery performance (DORA) links trunk-based development and short-lived branches with faster, safer releases. Keep branches alive for hours or a day or two, not weeks.

Semantic Versioning and Releases

Version releases as MAJOR.MINOR.PATCH, for example 2.4.1.

PartIncrease when
MAJORBreaking change
MINORNew backward compatible feature
PATCHBackward compatible bug fix
bash git tag -a v2.4.1 -m "Release 2.4.1" git push origin v2.4.1 gh release create v2.4.1 --generate-notes

Git Hooks

Hooks are scripts that Git runs at certain moments, stored in .git/hooks/. Common ones: pre-commit (run before a commit is created), commit-msg (check the message) and pre-push.

bash #!/usr/bin/env bash # .git/hooks/pre-commit (make it executable with chmod +x) if git diff --cached | grep -E "AKIA[0-9A-Z]{16}" >/dev/null; then echo "Possible AWS access key in commit. Aborting." exit 1 fi

Because .git/hooks is not shared, teams use the pre-commit framework to keep hooks in the repository:

yaml # .pre-commit-config.yaml repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 hooks: - id: end-of-file-fixer - id: trailing-whitespace - id: check-yaml - id: detect-private-key - repo: https://github.com/gitleaks/gitleaks rev: v8.21.2 hooks: - id: gitleaks
bash pip install pre-commit pre-commit install # installs the git hook pre-commit run --all-files
Version note: The rev values above are examples. Use the latest tags from each project when you set this up.

Signed Commits

Signing proves who made a commit. Use SSH signing, which is simple to set up:

bash git config --global gpg.format ssh git config --global user.signingkey ~/.ssh/id_ed25519.pub git config --global commit.gpgsign true git log --show-signature -1

Monorepo, Submodules and Large Files

  • Monorepo: many projects in one repository. Easy sharing, needs smart CI that builds only what changed
  • Submodules: include another repository at a fixed commit (git submodule add). Powerful but easy to misuse
  • Git LFS: store large binary files outside normal history
  • Shallow clone: git clone --depth 1 is faster in CI

Practice Tasks

  1. Fork a public repository, make a small change and open a pull request
  2. Enable branch protection on your own repo and prove that you cannot push directly to main
  3. Add CODEOWNERS and a pull request template
  4. Install pre-commit with a secret scanner and try to commit a fake key
  5. Tag a release and generate release notes with the GitHub CLI

Conclusion

Teams collaborate through pull requests, protected branches, automated checks and a clear branching strategy. Keep branches short, protect main, and let hooks and CI catch mistakes before humans review.

Quick Summary: PR flow; small PRs; branch protection + CODEOWNERS; trunk-based vs Gitflow; semver; hooks; signed commits.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators