Git Cheat Sheet · Branches
Link a branch to a remote branch
git branch --set-upstream-to=origin/<branch>
A local branch can "track" a remote branch, its upstream. That is the branch git pull and git push target without arguments, and the one Git uses to count how far ahead or behind you are.
What it does
Sets the tracked remote branch: it is the one targeted by pull and push, and by the ahead / behind counter.
A use case
You created your branch locally and a colleague has already published it under the same name.
On the command line
git branch --set-upstream-to=origin/<branch>- Links the current branch to a remote branch (short form:
-u). git push -u origin <branch>- Publishes the branch and links it in a single command.
git branch --unset-upstream- Removes the link.
git branch -vv- Shows the branch tracked by each local branch.
In Merathon
- Right-click the local branch → "Set tracked branch…" then enter "origin/branch".
- "Stop tracking a remote branch" removes the link.
Frequently asked questions
What does "The current branch has no upstream branch" mean?
The branch has never been published or linked. git push -u origin <branch> publishes it and fixes the problem once and for all.
How do I link new branches automatically?
git config --global push.autoSetupRemote true: the first git push creates and links the remote branch.