Checking Out a Remote Branch to Work On It
A teammate's feature branch exists only on the remote. Track it, commit, push — and see a real push failure, then fix it.
feature/dessert-menu has been sitting on the remote since you cloned — real commits, a real feature in progress, started by a teammate. To actually work on it, you need a real local branch that stays connected to that remote one.\n\ngit switch --track does both jobs in a single command: creates the local branch AND wires up upstream tracking, so a plain git push already knows where to go. This lesson also deliberately triggers the opposite, real failure — a brand-new branch with no upstream at all — so the difference is unmistakable.
Tracking a Remote Branch in One Step
git switch --track origin/feature/dessert-menu
git branch -vv
A real local branch, already wired to push to and pull from the matching remote branch — confirmed directly by branch -vv showing the tracking relationship.
Committing and Pushing, Already Connected
git add creme-brulee.md
git commit -m "Add creme brulee recipe"
git push
No -u needed — --track already set up the upstream relationship, so a plain push genuinely knows exactly where to send this commit.
The Real Failure, On Purpose
git switch -c experiment/new-idea
git push
fatal: The current branch experiment/new-idea has no upstream branch.
A brand-new branch, created with plain -c, has no tracking relationship at all — git genuinely does not know where "push" should go, and says so plainly rather than guessing.
The Real Fix
git push -u origin experiment/new-idea
Sends the branch and establishes tracking in the same step — from here on, plain git push on this branch works too.
git switch --track origin/<branch>
Creates a real local branch matching a remote-tracking branch's name, and sets up upstream tracking in the same step. Confirmed directly in this lab: the very next git push worked with no arguments and no -u flag needed.
Upstream branch
The real, specific remote branch a local branch is configured to push to and pull from by default. Confirmed directly in this lab: a branch WITHOUT one (created via plain switch -c) caused git push to genuinely refuse, rather than guess where to send the commit.
🔗 Track the Remote Branch
Check out feature/dessert-menu with real tracking set up in the same command.
cd ~/team-recipes && git switch --track origin/feature/dessert-menucd ~/team-recipes && git branch -vvstudent@lab:~$ cd ~/team-recipes && git switch --track origin/feature/dessert-menu branch 'feature/dessert-menu' set up to track 'origin/feature/dessert-menu'. Switched to a new branch 'feature/dessert-menu' student@lab:~$ cd ~/team-recipes && git branch -vv * feature/dessert-menu 390d424 [origin/feature/dessert-menu] Add panna cotta recipe master d891fe9 [origin/master] Add hot chocolate recipe
📸 Commit and Push, Already Connected
Add your own real commit to this branch and push it — no extra setup needed.
cd ~/team-recipes && printf 'Creme Brulee\n\nBake custard in a water bath, torch sugar topping before serving.\n' > creme-brulee.mdcd ~/team-recipes && git add creme-brulee.mdcd ~/team-recipes && git commit -m 'Add creme brulee recipe'cd ~/team-recipes && git pushstudent@lab:~$ cd ~/team-recipes && printf 'Creme Brulee\n\nBake custard in a water bath, torch sugar topping before serving.\n' > creme-brulee.md student@lab:~$ cd ~/team-recipes && git add creme-brulee.md student@lab:~$ cd ~/team-recipes && git commit -m 'Add creme brulee recipe' [feature/dessert-menu 9d5405c] Add creme brulee recipe 1 file changed, 3 insertions(+) create mode 100644 creme-brulee.md student@lab:~$ cd ~/team-recipes && git push Enumerating objects: 4, done. Counting objects: 100% (4/4), done. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 350 bytes | 38.00 KiB/s, done. Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 To ../recipes-origin.git 390d424..9d5405c feature/dessert-menu -> feature/dessert-menu
🚫 Trigger a Real Push Failure
Create a brand-new branch the plain way, with no tracking — and watch a plain push genuinely fail.
cd ~/team-recipes && git switch mastercd ~/team-recipes && git switch -c experiment/new-ideacd ~/team-recipes && git pushstudent@lab:~$ cd ~/team-recipes && git switch master Switched to branch 'master' Your branch is up to date with 'origin/master'. student@lab:~$ cd ~/team-recipes && git switch -c experiment/new-idea Switched to a new branch 'experiment/new-idea' student@lab:~$ cd ~/team-recipes && git push fatal: The current branch experiment/new-idea has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin experiment/new-idea To have this happen automatically for branches without a tracking upstream, see 'push.autoSetupRemote' in 'git help config'.
✅ Fix It With -u
Push this new branch for the first time, establishing tracking in the same step.
cd ~/team-recipes && git push -u origin experiment/new-ideastudent@lab:~$ cd ~/team-recipes && git push -u origin experiment/new-idea Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 To ../recipes-origin.git * [new branch] experiment/new-idea -> experiment/new-idea branch 'experiment/new-idea' set up to track 'origin/experiment/new-idea'.
Lab 2.1.3 complete. A remote branch tracked, committed to, and pushed — and a real push failure, understood and fixed:\n\n\n Remote branch tracked in one step : ✅ switch --track\n Commit pushed, no extra setup : ✅ confirmed\n Real push failure triggered : ✅ no upstream\n Fixed for real with -u : ✅ confirmed\n
Enable JavaScript to run the live terminal and track your progress.