Chapter 10 of 10 · Git and GitHub for Beginners — Complete Free Tutorial

Git Workflows and Project Best Practices

The final chapter of the Git and GitHub for Beginners series zooms out from individual commands to team habits. A workflow is simply an agreed set of rules about where commits go and how they reach main; picking one and following it is what makes a repository readable six months later.

Popular workflows at a glance

WorkflowShapeFits when
CentralisedEveryone commits to mainSolo projects or teaching basics
Feature branchOne short-lived branch per change, merged when doneSmall teams — the default choice
GitHub flowFeature branch → pull request → merge to a deployable mainContinuous deployment web apps
Git flowmain plus long-lived develop and release branchesVersioned software with scheduled releases
Trunk basedEveryone commits small changes straight to trunk behind flagsMature teams with strong automated tests

You do not need to master them all — feature branches plus pull requests, the GitHub flow core, will carry you through most of your career. The worst workflow is not a simple one; it is an inconsistent one.

Commit messages as project memory

Treat the log as documentation you can query. Beyond the imperative-mood habit from Staging and Committing, many teams adopt Conventional Commits: a typed prefix such as feat:, fix:, docs:, refactor:, test: or chore: followed by a short summary. Tooling then reads the history directly — generating changelogs, deciding whether a change is breaking, or triggering a release. Whatever style you choose, keep it uniform, keep subjects short, and make each commit one logical change so git log, git blame and git revert all tell a true story.

Protecting main and letting machines help

Teams that ship confidently put rules between good intentions and a bad merge. On GitHub you can require pull requests before merging, require a minimum number of approving reviews, require status checks to pass, and forbid force-pushes to main. The checks themselves come from GitHub Actions — workflow files in .github/workflows/ that run tests, linters and builds on every push and pull request. With protection on, the only way into main is a reviewed, tested branch, and nobody has to remember to be careful.

What belongs in the repository

  • Commit: source code, configuration with fake values, migration files, your .gitignore, small assets and the README.
  • Never commit: secrets and real .env files, dependencies (node_modules), build output (dist), editor folders and OS junk (.DS_Store).
  • Optional but valuable: pre-commit hooks (via tools like Husky) that lint before every commit, and a .gitattributes for consistent line endings across Windows and macOS.

A leaked key is an emergency: rotate the secret immediately, then decide whether history needs scrubbing — which is exactly the kind of job you met in Correcting History. Mark releases with annotated tags (git tag -a v1.0.0) so the world can always find the exact commit a version came from.

Habits that keep a repository healthy

  • Commit small, often and with purpose — a clean history is built, not rescued.
  • Pull before you start, push before you stop — keeps divergence tiny and reviews fresh.
  • Delete branches the moment they merge — the branch list should mirror active work.
  • Run git status before every commit — thirty seconds that prevents accidental commits.
  • Read other people's repositories — public projects on GitHub are free lessons in structure and workflow.
git log --graph --oneline --decorate -6

Expected output:

* 7a8b9c0 (HEAD -> main, origin/main) Update the menu prices
| * 3f4e5d6 (feature-online-orders) Add the order form validation
| * 1d2e3f4 Start the online orders page
|/
* 4c3b2a1 Fix the broken link in the footer
* 7e6d5c4 Style the navigation bar
* b2a1f0e Initial commit
git tag -a v1.0.0 -m "First public release"
git push origin v1.0.0

Expected output:

To github.com:sara-bakery/bakery-site.git
 * [new tag]         v1.0.0 -> v1.0.0

Common mistakes

  • No workflow at all — everyone commits where they like and main becomes a guessing game.
  • Committing secrets and pushing them — history remembers, so rotate the key first and only then worry about scrubbing.
  • Long-lived branches treated as backups — a branch is a line of work, not storage; merge or delete it.
  • Skipping CI because “it is a small change” — small changes are exactly what break production.
  • Mixing several workflows in one repository — pick one, document it in the README, and keep it consistent.

Practice checklist

  1. Read the workflow table again and write two sentences describing the workflow your current project follows (or should).
  2. Convert your next three commit messages to Conventional Commits style and check them with git log --oneline.
  3. Add a .gitignore entry for every junk file you have accidentally committed so far.
  4. Create an annotated tag on a milestone commit and push it with git push origin <tag>.
  5. Draft a branch-protection rule set (reviews plus passing checks) you would apply to main on a real team.

What's next?

You have travelled from “what is a snapshot?” to shipping reviewed, tagged, protected code — the complete beginner's arc. Revisit any chapter from the tutorials index whenever you need a refresher, and when your Git habits feel solid, continue your learning with JavaScript Best Practices and Next Steps to grow the projects you can now version with confidence.

Quiz: Git Workflows and Project Best Practices

5 questions · 70% to pass

Frequently Asked Questions

Git is a distributed version control system: it records snapshots of your project over time, lets you jump back to any point, branch off to try ideas safely, and merge other people's work. It is the industry standard — nearly every developer job assumes basic Git fluency — and it is the best insurance you can have against lost or broken code.

Git is the tool that runs on your machine and stores history locally; it works fully offline. GitHub is one of many websites (GitLab, Bitbucket) that hosts Git repositories in the cloud and adds collaboration features: pull requests, code review, issues and CI. You can use Git forever without GitHub — GitHub needs Git to be useful.

A repository (repo) is your project folder plus a hidden .git directory containing the entire history: every commit, branch and tag. It can be local (only on your computer) or remote (cloned on GitHub). Deleting .git loses the history but keeps your files; deleting the files while keeping .git leaves history with nothing to show.

git add moves changed files into the staging area — your draft of the next snapshot — so you can review exactly what will be recorded. git commit writes the staged snapshot permanently with a message describing why the change happened. Two steps by design: stage deliberately, commit intentionally.

A branch is a movable pointer to a commit — creating one costs almost nothing. Use a branch for every unit of work (feature, fix, experiment): it keeps unfinished code out of main, lets you review changes in a pull request, and makes abandoning a bad idea as simple as deleting the branch.

It depends on where the change lives. Unstaged edits: git restore file. Staged but uncommitted: git restore --staged file. Committed but not pushed: git reset --soft to keep changes staged. Already pushed: git revert commit — it writes a new commit that undoes the old one instead of rewriting shared history. The undoing chapter covers each case with commands.

A conflict happens when two branches changed the same lines and Git cannot choose automatically. Your file gets marked up with <<<<<<<, ======= and >>>>>>> sections; you edit it down to the correct result, remove the markers, then git add and git commit. Conflicts are normal, small and entirely fixable — they are not an error state.

A pull request (PR) is GitHub's proposal to merge one branch into another. It shows the diff, runs checks, and lets teammates comment line by line before the code lands. It is the centre of modern collaboration: work on a branch, open a PR, review, approve, merge.

Write the subject in imperative mood, under about 50 characters: "Add email validation to signup". Explain why, not what, in the body when it is not obvious. Many teams use Conventional Commits (feat:, fix:, docs:) so tools can generate changelogs — the workflows chapter shows the format in practice.

Secrets (API keys, .env files), dependencies (node_modules), build output (dist), and operating-system junk (.DS_Store, Thumbs.db). A .gitignore file excludes them from the start; the common mistakes chapter shows what to do if something already slipped into history.