What does git push -u (set upstream) do, and how does it change future push/pull behavior?
Last updated
git push -u (short for --set-upstream) pushes the branch and records a tracking link between your local branch and the remote branch, so future git push and git pull need no arguments.
What it sets:
Configures the branch's upstream (tracking) reference, e.g.
origin/feature.Stored in
.git/configunder the branch'sremoteandmergekeys.
Effect on later commands:
Bare
git pushandgit pullnow know the target automatically.git statuscan report ahead/behind counts vs the upstream.
You only need
-uonce per branch; after that the link persists.
[lang:bash]
git push -u origin feature # first push, sets tracking
git push # later: no args needed
git pull # pulls from origin/feature
- https://git-scm.com/docs/git-push
- https://adamj.eu/tech/2022/10/31/git-how-to-automatically-create-upstream-branches/
- https://gitlab.com/git-scm/git/-/blob/HEAD/Documentation/RelNotes/2.16.0.adoc
- https://www.git-tower.com/learn/git/faq/set-upstream
- https://www.warp.dev/terminus/understanding-git-push-origin
- https://forum.freecodecamp.org/t/what-does-u-mean-in-this/635014