The option -uis an abbreviation for --set-upstream.
This option is given the first time pusha branch is made to a remote repository, and adds "tracking" information to the branch. It basically serves so that when you later do git pull, since that command does not receive parameters, git can know where to download the changes from. It will also work if you do git pushwithout more parameters.
It is not necessary to specify again -uin the following operations push, since the association of the branch with the remote has already been saved by git.
Low-level technical details
All this information git saves it in a hidden folder (inside the working folder) called .git, in the file .git/configand updates it through the options that we are explaining.
Specifically, the part in which the branch is associated mainwith the remote originwould be recorded in a part of that file that looks like this:
From that information, when you do git pullwithout parameters, or git push, git will know what to do, because:
It will look at which branch you are on at that moment (it queries it in .git/HEADand finds that you are for example in branch main)
It will look at which remote is associated with that branch (it consults that in the file .git/config, in the part labeled with [branch "main"], and determines that the associated repository is the one called origin)
It will look at which url the repository refers to origin(again check the file .git/configunder the section [remote "origin"]and discover the URL
It will connect to that URL to download the remote commits you don't have locally and merge them into the local branch (in case of a git pull), or push local commits that aren't on the remote (in case of a git push).
Note . It would also be possible to associate the local branch mainwith a branch that has a different name on the remote. For that you would do for example git push -u origin main:otro_nombre. When you don't specify that second part of the upstream, the same name as the local branch will be used, so it is git push -u origin main:mainequivalent to git push -u origin main:main.
git push -u repositoryIt basically does a upstreamon every updated repository branch push. In a nutshell, it keeps track of all the changes the branch has received.
In case you need information about these commands, use git --help gitfor an explanation of the vast majority of git commands.
The -u option refers to upstream. When you call the -u option, what you are doing is referencing the main remote repository. It is used when you have multiple remote repos and want to switch between them. (See switch to bitbucket or gitlab instead of github). Also, (as @abulafia has indicated) when you have only one repository, it helps you to associate the branch with the remote in question.
The option
-u
is an abbreviation for--set-upstream
.This option is given the first time
push
a branch is made to a remote repository, and adds "tracking" information to the branch. It basically serves so that when you later dogit pull
, since that command does not receive parameters, git can know where to download the changes from. It will also work if you dogit push
without more parameters.It is not necessary to specify again
-u
in the following operationspush
, since the association of the branch with the remote has already been saved by git.Low-level technical details
All this information git saves it in a hidden folder (inside the working folder) called
.git
, in the file.git/config
and updates it through the options that we are explaining.Specifically, the part in which the branch is associated
main
with the remoteorigin
would be recorded in a part of that file that looks like this:And what is the URL associated with the repository
origin
would be in the part.git/config
that looks like this:From that information, when you do
git pull
without parameters, orgit push
, git will know what to do, because:.git/HEAD
and finds that you are for example in branchmain
).git/config
, in the part labeled with[branch "main"]
, and determines that the associated repository is the one calledorigin
)origin
(again check the file.git/config
under the section[remote "origin"]
and discover the URLgit pull
), or push local commits that aren't on the remote (in case of agit push
).Note . It would also be possible to associate the local branch
main
with a branch that has a different name on the remote. For that you would do for examplegit push -u origin main:otro_nombre
. When you don't specify that second part of the upstream, the same name as the local branch will be used, so it isgit push -u origin main:main
equivalent togit push -u origin main:main
.git push -u repository
It basically does aupstream
on every updated repository branch push. In a nutshell, it keeps track of all the changes the branch has received.In case you need information about these commands, use
git --help git
for an explanation of the vast majority of git commands.The -u option refers to upstream. When you call the -u option, what you are doing is referencing the main remote repository. It is used when you have multiple remote repos and want to switch between them. (See switch to bitbucket or gitlab instead of github). Also, (as @abulafia has indicated) when you have only one repository, it helps you to associate the branch with the remote in question.