This lesson combines 2 topics: Release Management and Fork/Upstream Sync — Agency & Contractor Pattern.
Learning Objectives
- Create and manage Git tags (annotated vs lightweight)
- Understand Semantic Versioning (MAJOR.MINOR.PATCH) and its rules
- Master the release branch workflow and the hotfix flow
- Automate changelogs with conventional-changelog
- Create GitHub Releases and sign tags with GPG
- Understand the triangular workflow (fork ↔ upstream)
- Set up an
upstreamremote pointing to the client repository - Practice the sync flow: fetch upstream → rebase → safely force-push to the fork
- Handle conflicts when rebasing many commits onto the latest upstream
- Handle bidirectional sync when the client merges back
Part 1: Release Management
1. Git Tags — Marking Versions
Two kinds of tags
# Lightweight tag — simple, just a pointer to a commit
git tag v1.0.0
# Annotated tag — recommended for releases — has author, date, message
git tag -a v1.0.0 -m "Release version 1.0.0 — initial stable release"
# Tag an older commit (not HEAD)
git tag -a v0.9.0 abc1234 -m "Release v0.9.0"
# List tags
git tag
git tag -l "v1.*" # filter by pattern
# Show annotated tag details
git show v1.0.0
Key differences
Pushing tags to the remote
# Push a specific tag
git push origin v1.0.0
# Push all tags
git push origin --tags
# Delete a local tag
git tag -d v1.0.0-beta
# Delete a remote tag
git push origin :refs/tags/v1.0.0-beta
# Or:
git push origin --delete v1.0.0-beta
2. Semantic Versioning — MAJOR.MINOR.PATCH
Semantic Versioning (SemVer) is a standard for naming software versions. Source: semver.org.
Version bump rules
MAJOR.MINOR.PATCH
MAJOR: bump on a breaking change (backward-incompatible API)
MINOR: bump when adding a new feature (backward-compatible)
PATCH: bump when fixing a bug (backward-compatible)
Examples:
1.2.3 → 1.2.4 (bug fix)
1.2.3 → 1.3.0 (new feature, PATCH resets to 0)
1.2.3 → 2.0.0 (breaking change, MINOR + PATCH reset to 0)
Pre-release and build metadata
# Pre-release (order: alpha < beta < rc < stable)
v1.0.0-alpha.1
v1.0.0-beta.3
v1.0.0-rc.1
v1.0.0
# Build metadata (does not affect ordering, informational only)
v1.0.0+build.42
v1.0.0-beta.1+sha.abc1234
Combining with Conventional Commits
# Conventional Commits let automation determine the version bump:
#
# feat: add OAuth login → MINOR bump (1.2.3 → 1.3.0)
# fix: resolve token expiry bug → PATCH bump (1.2.3 → 1.2.4)
# feat!: redesign auth API → MAJOR bump (1.2.3 → 2.0.0)
# BREAKING CHANGE: footer text → MAJOR bump
#
# chore/docs/style commits → no version bump
3. Release Branch Workflow
Git Flow Release Branch
Creating and working with a release branch
# 1. Create the release branch from develop at feature freeze
git switch develop
git pull origin develop
git switch -c release/1.2.0
# 2. On the release branch: only bug fixes, version number updates, docs
# NO new features
echo "1.2.0" > VERSION
npm version 1.2.0 --no-git-tag-version # update package.json
git add VERSION package.json
git commit -m "chore: bump version to 1.2.0"
# 3. Merge into main when ready to release
git switch main
git merge --no-ff release/1.2.0 -m "chore: release v1.2.0"
git tag -a v1.2.0 -m "Release v1.2.0"
git push origin main --tags
# 4. Merge back into develop to sync the bug fixes
git switch develop
git merge --no-ff release/1.2.0 -m "chore: sync release/1.2.0 back to develop"
git push origin develop
# 5. Delete the release branch
git branch -d release/1.2.0
git push origin --delete release/1.2.0
4. Hotfix Flow
A hotfix addresses a critical bug directly on production.
5. Automated Changelog
Conventional Changelog
# Install
npm install -g conventional-changelog-cli
# Generate CHANGELOG.md from commit history (Conventional Commits format)
conventional-changelog -p angular -i CHANGELOG.md -s
# -p angular: use the Angular preset (feat/fix/perf/docs/...)
# -i CHANGELOG.md: input file
# -s: write output to input file (overwrite if needed)
# Generate from scratch (entire history)
conventional-changelog -p angular -i CHANGELOG.md -s -r 0
Example of a generated CHANGELOG.md
# Changelog
## [1.2.0] - 2024-01-15
### Features
* add OAuth 2.0 integration with Google ([abc1234])
* add dark mode support ([def5678])
### Bug Fixes
* resolve token refresh race condition ([ghi9012])
## [1.1.0] - 2024-01-01
...
Integrating with npm scripts
Note (2026):
standard-versionhas been deprecated since May 2022. Recommended replacements:semantic-release(fully automated, most popular),release-please(by Google, creates a release PR), orcommit-and-tag-version(a community fork continuing standard-version). The example below illustrates how the mechanism works — don't use standard-version for new projects.
{
"scripts": {
"release": "standard-version",
"release:minor": "standard-version --release-as minor",
"release:major": "standard-version --release-as major"
}
}
# standard-version automatically:
# 1. Calculates the version bump from commits
# 2. Updates the package.json version
# 3. Creates/updates CHANGELOG.md
# 4. Creates the commit "chore(release): v1.2.0"
# 5. Creates the annotated tag v1.2.0
npm run release
6. GitHub Releases
GitHub Releases extend Git tags with release notes, binary assets, and download links.
# Create a GitHub Release via the CLI (gh)
gh release create v1.2.0 \
--title "Version 1.2.0 — OAuth & Dark Mode" \
--notes-file RELEASE_NOTES.md \
--target main
# Upload artifacts to the release
gh release upload v1.2.0 dist/app-linux.tar.gz dist/app-macos.tar.gz
# Create a draft release (not yet published)
gh release create v1.3.0-rc.1 --draft --prerelease
# View releases
gh release list
gh release view v1.2.0
Auto-generating release notes from PR titles
# .github/release.yml — configuration for auto-generated notes
changelog:
categories:
- title: "Breaking Changes"
labels: ["breaking-change"]
- title: "New Features"
labels: ["enhancement", "feature"]
- title: "Bug Fixes"
labels: ["bug"]
- title: "Documentation"
labels: ["documentation"]
7. Signed Tags with GPG
Signed tags prove the identity of whoever created the release — important for security-sensitive projects.
# Check whether you already have a GPG key
gpg --list-secret-keys --keyid-format=long
# If not, generate a new GPG key
gpg --gen-key
# Get the key ID (looks like ABCD1234EFGH5678)
gpg --list-secret-keys --keyid-format=long | grep sec
# Configure Git to use the GPG key
git config --global user.signingkey ABCD1234EFGH5678
git config --global gpg.program gpg
# Create a signed tag (-s instead of -a)
git tag -s v1.2.0 -m "Release v1.2.0 (signed)"
# Verify the tag signature
git tag -v v1.2.0
# Output: gpg: Good signature from "Your Name <your@email.com>"
# Sign all tags automatically
git config --global tag.gpgSign true
# Push a signed tag (same as a normal push)
git push origin v1.2.0
Part 2: Fork/Upstream Sync — Agency & Contractor Pattern
1. Context: The Agency/Contractor Pattern
A real-world scenario: your company (the agency) builds a project for a client. The client has its own repository. Workflow:
2. Initial Setup
# 1. Clone the agency's fork (origin is set up automatically)
git clone https://github.com/your-agency/project-repo.git
cd project-repo
# 2. Add upstream (the client repository)
git remote add upstream https://github.com/client-org/project-repo.git
# 3. Check the remotes
git remote -v
# origin https://github.com/your-agency/project-repo.git (fetch)
# origin https://github.com/your-agency/project-repo.git (push)
# upstream https://github.com/client-org/project-repo.git (fetch)
# upstream https://github.com/client-org/project-repo.git (push)
# Best practice: only fetch from upstream, never push directly to upstream
# (a PR is the right way to contribute code upstream)
git remote set-url --push upstream DISABLE
# Now "git push upstream" fails — prevents accidental pushes
# Verify
git remote -v
# upstream https://github.com/client-org/project-repo.git (fetch)
# upstream DISABLE (push)
3. Daily Sync Flow
Every day before you start working:
# Step 1: Fetch all updates from upstream
git fetch upstream
# remote: Enumerating objects: 23, done.
# remote: Counting objects: 100% (23/23), done.
# From https://github.com/client-org/project-repo
# abc1234..def5678 main -> upstream/main
# xyz9012..uvw3456 develop -> upstream/develop
# Step 2: Rebase local main onto upstream/main
git switch main
git rebase upstream/main
# Successfully rebased and updated refs/heads/main.
# Step 3: Sync origin (the team fork) with upstream
git push origin main
# If origin already has divergent history (someone pushed directly), use --force-with-lease:
git push origin main --force-with-lease
# Step 4: Rebase the feature branch you're working on onto the latest main
git switch feature/my-task
git rebase main
Why rebase instead of merge?
# Merge: creates a merge commit on every sync → messy fork history in the PR
#
# git merge upstream/main
#
# * abc1234 Merge remote-tracking branch 'upstream/main' ← bad, unnecessary
# * def5678 feat: my feature
# Rebase: linear history, easy-to-review PR
#
# git rebase upstream/main
#
# * def5678 feat: my feature ← your commit sits on top of upstream
# * [upstream commits]
4. Triangular Workflow — Push to Fork, PR to Upstream
# Standard workflow:
# 1. Sync (as above)
# 2. Create a feature branch
git switch -c feature/new-api-endpoint
# 3. Code and commit
git add . && git commit -m "feat: add /api/v2/users endpoint"
git add . && git commit -m "feat: add pagination to user list"
# 4. Before pushing, rebase onto the latest upstream
git fetch upstream
git rebase upstream/main
# On conflict → resolve it (see section 5)
# 5. Push the feature branch to the fork (origin)
git push origin feature/new-api-endpoint
# 6. Create a PR from fork → upstream on GitHub
gh pr create \
--repo client-org/project-repo \
--head your-agency:feature/new-api-endpoint \
--base main \
--title "feat: add /api/v2/users endpoint with pagination" \
--body "..."
5. Handling Conflicts When Rebasing Many Commits
When you rebase a long-running feature branch onto an upstream that has many new commits:
git fetch upstream
git rebase upstream/main
# Rebasing many commits — each commit may conflict:
# CONFLICT (content): Merge conflict in src/api/users.ts
# error: could not apply a1b2c3d... feat: add /api/v2/users endpoint
# See which commit the current conflict is in
git status
# rebase in progress; onto upstream/main
# Currently rebasing branch 'feature/new-api-endpoint' on 'abc9876'
# Resolve the conflict (see the day-03 lesson)
vim src/api/users.ts
git add src/api/users.ts
git rebase --continue
# If the next commit conflicts too → resolve again → continue
# ...until done
# Skip the current commit (if upstream has already handled it)
git rebase --skip
# Abort the whole rebase and return to the previous state
git rebase --abort
Rebasing many commits with rerere
# Enable rerere to reuse conflict resolutions (important when you rebase often)
git config rerere.enabled true
# The first time you resolve a conflict in commit A → rerere remembers it
# Next time you rebase and hit the identical conflict → rerere applies it automatically
6. Safely Force-Pushing to the Fork
After a rebase, you need to force-push to update the fork:
# NOT safe — wipes out teammates' commits if they pushed to the same branch
git push origin feature/new-api-endpoint --force
# SAFE — checks the remote-tracking ref before pushing
git push origin feature/new-api-endpoint --force-with-lease
# If a teammate has pushed to that feature branch:
# error: failed to push some refs
# hint: Updates were rejected because the remote contains work that you do
# hint: not have locally.
# → You must fetch and resolve the conflict first
# Set up an alias for convenience
git config --global alias.fpush 'push --force-with-lease'
git fpush origin feature/new-api-endpoint
When is force-pushing allowed?
OK to force-push:
✓ Personal branch (only you work on it)
✓ Feature branch nobody else has checked out
✓ After telling the team: "I'm rebasing + force-pushing feature/X"
DO NOT force-push:
✗ main, develop, release/* — shared branches
✗ A branch with an open PR where reviewers left line-number comments
(rebase changes commit hashes → comments lose their context)
✗ Without --force-with-lease (always use --force-with-lease)
7. Bidirectional Sync: Client Merges Back
When the client accepts your team's PR into upstream, the fork needs to be synced again:
# After the PR is merged into upstream/main:
git fetch upstream
git switch main
git rebase upstream/main
# Origin (the fork) needs updating
git push origin main
# If main has diverged:
git push origin main --force-with-lease
# Delete the merged branch (local + remote)
git branch -d feature/new-api-endpoint
git push origin --delete feature/new-api-endpoint
When the client has a hotfix that didn't go through a PR
Sometimes the client pushes directly to upstream without going through the team's PR:
# Detect: upstream/main has commits that origin/main doesn't
git fetch upstream
git log origin/main..upstream/main --oneline
# abc1234 hotfix: patch critical security issue (from client team)
# Sync the fork with upstream
git switch main
git rebase upstream/main
git push origin main --force-with-lease
# Rebase all active feature branches onto the new main
git switch feature/my-ongoing-work
git rebase main
8. Divergent History and Reflog Recovery
When history has diverged too far
# Measure how far it has diverged
git log origin/main..upstream/main --oneline | wc -l # how many commits upstream is ahead
git log upstream/main..origin/main --oneline | wc -l # how many commits the fork is ahead
# If the fork has commits it shouldn't (accidental commits directly on main):
# Option 1: Reset fork/main to upstream/main
git switch main
git reset --hard upstream/main
git push origin main --force-with-lease
# Option 2: If you need to keep a few specific commits from the fork
git log upstream/main..origin/main --oneline # commits only in the fork — note the hashes BEFORE resetting
git reset --hard upstream/main
git cherry-pick <commit-hash>
git push origin main --force-with-lease
Recovering lost commits via reflog
# Scenario: a bad rebase → commits "disappear"
git reflog
# abc1234 HEAD@{0}: rebase (finish): returning to refs/heads/feature/X
# def5678 HEAD@{3}: commit: feat: my important commit ← the lost commit
# ...
# Recover the lost commit
git checkout -b recovery/feature-x def5678
# Or cherry-pick:
git cherry-pick def5678
# If the rebase went completely wrong, go back to ORIG_HEAD
git reset --hard ORIG_HEAD
# (Git sets ORIG_HEAD automatically before a rebase/merge)
Review Questions
-
When should you bump the MAJOR version under SemVer?
Show answer
Bump MAJOR when there is a breaking change — a backward-incompatible change to the API/interface. Examples: renaming a public function, removing an endpoint, changing the request/response format, changing a function signature.
1.2.3 → 2.0.0(MINOR and PATCH reset to 0). Conventional Commits signal this withfeat!:,fix!:, or aBREAKING CHANGE:footer. -
What is the main difference between an annotated tag and a lightweight tag?
Show answer
Lightweight tag: just a pointer to a commit with no metadata of its own — like a branch that never moves. Annotated tag: creates its own tag object in
.git/objects/with tagger name, email, date, message, and can be GPG-signed.git describeprefers annotated tags. Use annotated tags for public releases (verifiable, full metadata); lightweight tags for private/temporary markers. -
Why must a hotfix be merged into both
mainanddevelop?Show answer
main= production code → needs the fix right away to deploy.develop= the integration branch for the next release → if you don't merge the hotfix into it, the bug will reappear in the next release (develop doesn't have the fix). This is a common mistake in Git Flow: merging only into main and thinking you're done, while develop still has the bug. Always merge the hotfix branch into both. -
What does
conventional-changelogrequire from the commit history to work well?Show answer
The commit history must follow the Conventional Commits format (
feat:,fix:,docs:,chore:,BREAKING CHANGE:...). The tool parses commit messages to classify them and generate the changelog. If commit messages don't follow the format (e.g. "update stuff", "fix bug"), the tool can't classify them and the changelog will be incomplete/wrong. Enforce it withcommitlint+ a Husky hook. -
Which command deletes a tag on the remote repository?
Show answer
git push origin --delete v1.0.0-betaor the older syntaxgit push origin :refs/tags/v1.0.0-beta. Remember to delete the local tag too:git tag -d v1.0.0-beta. Deleting a tag on the remote does not delete the local tag and vice versa — you need to do both steps separately. -
Why should you disable the push URL for the
upstreamremote?Show answer
To prevent accidentally pushing directly to upstream (the client's repository). The rule: contribute code only via PRs from fork → upstream, never push directly.
git remote set-url --push upstream DISABLEmakesgit push upstreamfail immediately — reminding you to use a PR. You can stillgit fetch upstreamas usual. -
While rebasing a feature branch onto upstream/main you hit a conflict in the 3rd commit. What do you do after resolving it?
Show answer
(1) Edit the file to resolve the conflict, (2)
git add <file>, (3)git rebase --continue. Git finishes applying the 3rd commit and then continues with the following commits — you may hit more conflicts in later commits. To skip the current commit (already handled by upstream):git rebase --skip. To cancel everything:git rebase --abort. -
What does
--force-with-leaseprotect against compared to--force?Show answer
--force-with-leasechecks whether the local remote-tracking ref (e.g.origin/feature/x) matches the actual remote. If a teammate pushed to that branch while you were rebasing, your local remote-tracking ref is stale → Git refuses the push.--forceoverwrites unconditionally and can silently wipe out teammates' commits. -
After a PR is merged into upstream, what must you do to keep the fork in sync?
Show answer
(1)
git fetch upstreamto update the remote-tracking branches, (2)git switch main && git rebase upstream/mainto sync local main, (3)git push origin main(may need--force-with-lease) to update the fork, (4)git branch -d feature/my-branch && git push origin --delete feature/my-branchto clean up the merged branch. -
Which command shows the commits that are in upstream but not yet in the fork?
Show answer
git log origin/main..upstream/main --oneline — shows commits in upstream/main that are not yet in origin/main (the fork). Remember to git fetch upstream first to update the remote-tracking refs. For the reverse direction (fork ahead of upstream): git log upstream/main..origin/main --oneline.
Hands-on Exercises
Part 1: Release Management
mkdir release-lab && cd release-lab
git init -b main
git config user.name "Dev" && git config user.email "dev@test.com"
# Create a few commits following Conventional Commits
echo "version: 1.0.0" > package.json
git add . && git commit -m "feat: initial project setup"
echo "login handler" > auth.js
git add . && git commit -m "feat: add OAuth login"
echo "bug fix" >> auth.js
git add . && git commit -m "fix: resolve token refresh bug"
# Create annotated tag v1.0.0
git tag -a v1.0.0 -m "Release v1.0.0 — initial stable release"
git show v1.0.0
# Add commits after the release
echo "dark mode" > theme.js
git add . && git commit -m "feat: add dark mode support"
# Create a release branch
git switch -c release/1.1.0
echo "1.1.0" > VERSION
git add . && git commit -m "chore: bump version to 1.1.0"
# Merge into main and tag
git switch main
git merge --no-ff release/1.1.0 -m "chore: release v1.1.0"
git tag -a v1.1.0 -m "Release v1.1.0"
# View the full graph
git log --oneline --graph --all
# Simulate a hotfix
git switch -c hotfix/1.1.1
echo "critical fix" >> auth.js
git add . && git commit -m "fix: patch critical security vulnerability"
git switch main
git merge --no-ff hotfix/1.1.1 -m "chore: hotfix v1.1.1"
git tag -a v1.1.1 -m "Hotfix v1.1.1"
# View the tags
git tag -l
git log --oneline --graph --all
Part 2: Fork/Upstream Sync — Agency & Contractor Pattern
# Simulate the triangular workflow with 2 local repositories
mkdir upstream-sim && cd upstream-sim
git init --bare -b main upstream.git
mkdir client-work && cd client-work
git clone ../upstream.git .
git config user.name "Client" && git config user.email "client@test.com"
echo "initial" > README.md
git add . && git commit -m "feat: initial commit"
git push origin main
cd ..
# "Fork" — clone upstream as the agency's origin
mkdir agency-fork && cd agency-fork
git clone ../upstream.git .
git config user.name "Agency Dev" && git config user.email "dev@agency.com"
git remote add upstream ../upstream.git
git remote set-url --push upstream DISABLE
git remote -v
# The client adds commits to upstream
cd ../client-work
echo "client feature" >> README.md
git add . && git commit -m "feat: client adds new feature"
git push origin main
# The agency syncs with upstream
cd ../agency-fork
git fetch upstream
git log upstream/main --oneline # see the client's new commit
git switch main
git rebase upstream/main # sync
git log --oneline # linear history
# The agency creates a feature branch and works on it
git switch -c feature/agency-work
echo "agency feature" >> README.md
git add . && git commit -m "feat: agency adds API endpoint"
# Before pushing, sync with the latest upstream (assume the client pushed more)
cd ../client-work
echo "another client commit" >> README.md
git add . && git commit -m "feat: client hotfix"
git push origin main
cd ../agency-fork
git fetch upstream
git rebase upstream/main # rebase the feature branch onto the latest upstream
git log --oneline --graph --all
References
- Semantic Versioning 2.0.0
- Git Tagging
- conventional-changelog
- GitHub: Managing releases
- Git Tools: Signing Your Work
- GitHub: Fork a repo
- GitHub: Syncing a fork
- git rebase documentation
- git remote documentation
- Atlassian: Forking Workflow