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.
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.
git 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.
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.
Takeaways
- git switch --track origin/<branch> creates a local branch and sets up upstream tracking in one real step
- A branch with upstream tracking already configured accepts a plain git push with no arguments
- A branch created with plain switch -c or branch has no upstream — git push genuinely refuses rather than guessing
- git push -u origin <branch> fixes this by sending the branch and establishing tracking in the same step