Git: Beginner to Advanced
Team workflows
Use Git reliably on a shared project.
Lesson 9 of 12
Reading: about 6 min
Lesson + practice: about 15 min
Difficulty: Advanced
On this page5 sections
Use Git reliably on a shared project. Follow the animated example, then use the sections below to review each idea.
Visual walkthrough
Use the player controls or jump menu to inspect each step. The diagram changes as the example moves forward.
The player shows one focused example. The sections below explain the ideas behind each topic.
Knowing the commands is half of working in a team. The other half is an agreed routine: how work gets from your laptop to the shared main, who checks it, and how releases are marked. A good routine keeps main always working and makes every change easy to review and easy to find later.
This lesson follows one small change through that routine, as the walkthrough above does. The shared repository is https://github.com/your-team/planner.git; progress lines from the hosting service are left out, and commit IDs will differ.
Trunk-based work
In trunk-based development, everyone integrates into one main branch (the “trunk”) often, at least daily. Work happens on short-lived branches that live for hours or a couple of days, not weeks. Small branches mean small reviews, fewer conflicts, and problems that are found while the change is still fresh in your mind.
Start every change from an up-to-date main
Always begin by updating main, then branch from it. Already up to date here means nobody pushed since you last pulled.
git switch main
git pull --ff-only
git switch -c add-filter$ git switch main
Already on 'main'
Your branch is up to date with 'origin/main'.
$ git pull --ff-only
Already up to date.
$ git switch -c add-filter
Switched to a new branch 'add-filter'Commit and publish the branch
Keep the change focused on one thing. -u links the branch to origin/add-filter, so later pushes are just git push.
git commit -m "Add search filter"
git push -u origin add-filter$ git commit -m "Add search filter"
[add-filter c06d429] Add search filter
1 file changed, 1 insertion(+)
create mode 100644 filter.js
$ git push -u origin add-filter
To https://github.com/your-team/planner.git
* [new branch] add-filter -> add-filter
branch 'add-filter' set up to track 'origin/add-filter'.Review and protected branches
Teams usually forbid pushing straight to main. On GitHub, GitLab and Bitbucket this is a protected branch rule, set in the repository settings by an administrator. Common rules:
- Changes reach
mainonly through a pull request. - At least one teammate must approve the pull request.
- Automated checks, such as tests and linting, must pass first.
- Force pushes and deleting the branch are blocked.
With protection on, a direct git push origin main is rejected by the server, and the message names the rule that blocked it. That is the system working: open a pull request instead.
| As the author | As the reviewer |
|---|---|
| Keep the pull request small and focused | Check it does what the description says |
| Explain what changed and why | Look for bugs, missing tests and unclear names |
| Review your own diff first | Ask questions instead of demanding rewrites |
| Reply to every comment | Approve once concerns are resolved |
Tags and releases
Branches move; a tag does not. A tag is a permanent name for one commit, used to mark releases such as v1.0.0 so anyone can find exactly what was shipped.
Create an annotated tag
-a makes an annotated tag, which stores who tagged it, when, and a message. Use annotated tags for releases.
git tag -a v1.0.0 -m "First release"
git tag
git show v1.0.0 --no-patch$ git tag -a v1.0.0 -m "First release"
$ git tag
v1.0.0
$ git show v1.0.0 --no-patch
tag v1.0.0
Tagger: Alex Bennett <alex@example.com>
Date: Tue Oct 20 09:03:00 2026 +0100
First release
commit 16b8dd77ff5de4fa276a9d7b5547d4865219d348
Author: Alex Bennett <alex@example.com>
Date: Tue Oct 20 09:02:00 2026 +0100
Add search filterTags stay put while main moves on
After another commit, git describe says the current commit is 1 commit after v1.0.0; g38b5603 is its ID. The log shows the tag still on the release commit.
git describe --tags
git log --oneline --decorate$ git describe --tags
v1.0.0-1-g38b5603
$ git log --oneline --decorate
38b5603 (HEAD -> main) Fix filter on mobile
16b8dd7 (tag: v1.0.0) Add search filter
97009a9 Add README$ git push origin v1.1.0
To https://github.com/your-team/planner.git
* [new tag] v1.1.0 -> v1.1.0| Change | Bump | Example |
|---|---|---|
| Bug fix, nothing else changes | PATCH | 1.0.0 → 1.0.1 |
| New feature, existing use still works | MINOR | 1.0.1 → 1.1.0 |
| Change that breaks existing use | MAJOR | 1.1.0 → 2.0.0 |
Collaboration exercise
Practise the full routine with a friend, or with two clones of one repository on your own computer:
- Update
mainwithgit pull --ff-only, then create a branch for one small change. - Commit, then
git push -u origin your-branch. - Open a pull request, ask for a review, and push a follow-up commit for any feedback.
- Merge the approved pull request on the hosting site.
- Clean up locally, as shown below.
Tidy up after the merge
Pull brings the merged work into main. -d deletes your local branch because its commits are now in main. --prune removes origin/add-filter, the remote-tracking name for the branch that was deleted on the server.
git switch main
git pull --ff-only
git branch -d add-filter
git fetch --prune$ git switch main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
$ git pull --ff-only
From https://github.com/your-team/planner
97009a9..09d65b8 main -> origin/main
Updating 97009a9..09d65b8
Fast-forward
filter.js | 1 +
1 file changed, 1 insertion(+)
create mode 100644 filter.js
$ git branch -d add-filter
Deleted branch add-filter (was c06d429).
$ git fetch --prune
From https://github.com/your-team/planner
- [deleted] (none) -> origin/add-filterYour push to main is rejected because the branch is protected. What should you do?
Reveal answer
Push your work to a branch instead, with git push -u origin your-branch, and open a pull request. The protection is intentional: changes reach main through review.
You tagged v2.0.0 and ran git push. Can teammates see the tag?
Reveal answer
No. git push does not send tags. Run git push origin v2.0.0 to share it.
Your progress
Reveal the check answer or reach the end to complete this lesson.