Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Last updated: Monday 09 November 2026 @ 12:56:44

Git Anti-patterns

Git · Collaboration and quality

Git anti-patterns

Recognise risky Git practices, reproduce their consequences safely, and replace them with reviewable workflows.

GitCode reviewProtected branchesReproducibility
Recognise risks

Explain why unreviewed changes and history rewriting can harm a team.

Practise alternatives

Use feature and hotfix branches rather than editing the mainline directly.

Review changes

Investigate diffs and evidence before accepting a change.

Common anti-patterns

Anti-patternProblemPrefer instead
Developing features directly on mainUnfinished work becomes the default branchShort-lived feature branch and reviewed integration
Committing urgent fixes directly to mainUrgency can bypass verificationSmall hotfix branch, focused test and expedited review
Self-approving a pull requestMissing independent reviewA collaborator checks functionality, clarity and scope
Force-pushing a shared mainlineOther developers’ history can be invalidatedProtect mainline branches; coordinate history changes
Large, unrelated commitsHard to review or revertSmall, purposeful commits
Committing secretsCredentials may persist in repository historyEnvironment variables, secret managers and immediate revocation

Practical: replace a direct commit with a reviewed change

  1. Create a fresh local repository.

    mkdir -p ~/git-antipattern-lab && cd ~/git-antipattern-lab
    git init -b main
    git config user.name "Git Student"
    git config user.email "student@example.invalid"
    printf '# Project rules\n\nKeep documentation accurate.\n' > README.md
    git add README.md
    git commit -m "docs: initialise rules"
  2. Create a feature branch and deliberately introduce a typo in a new file.

    git switch -c feature/install-guide
    printf 'Instalation steps:\n1. Connect the board.\n' > INSTALL.md
    git add INSTALL.md
    git commit -m "docs: add installation guide"
  3. Review the proposed change before merging.

    git diff main...feature/install-guide
    git log --oneline main..feature/install-guide
  1. Fix the spelling in INSTALL.md using a text editor (or the command below); keep the installation instructions intact.

    sed -i 's/Instalation/Installation/' INSTALL.md
  2. Commit the corrected file and inspect the complete feature diff again.

    git add INSTALL.md
    git commit -m "docs: correct installation heading"
    git diff main...feature/install-guide
  3. Integrate the reviewed feature locally and confirm the result.

    git switch main
    git merge --no-ff feature/install-guide -m "merge: installation guide"
    git log --oneline --graph --decorate --all
    cat INSTALL.md

Production defects and hotfixes

  1. Start from the current, stable main and create a hotfix branch.

    git switch main
    git switch -c hotfix/install-heading
  2. Add a short troubleshooting instruction to INSTALL.md, then commit it.

    printf '\nIf the board is not detected, check the USB cable.\n' >> INSTALL.md
    git add INSTALL.md
    git commit -m "fix: document USB troubleshooting"
  3. Inspect the change and return it to main using a merge.

    git diff main...hotfix/install-heading
    git switch main
    git merge --no-ff hotfix/install-heading -m "merge: USB documentation hotfix"

Additional anti-patterns to discuss