I just got started with a tutorial on Git.
There, they mentioned a command
git push -u origin master
where the changes made on local branch master
are pushed to origin
repository(on Github).
And the -u
tells git to remember the parameters so that next time we can just write git push
Can someone tell me whether git remembers the parameters only for the very next time we use git push
, or every time henceforth till a command to tell git to forget the parameters is written? Also, is any there such command?
Thanks in advance!
In the command
git push -u origin master
The -u
flag means that your local branch will become a tracking branch. That is, a branch that tracks a remote branch, so that future git pull
will know which branch to merge from and git push
will be directed to the correct remote branch.
Technically, the tracking adds the following information about the master branch to your .git/config
file:
[branch "master"]
remote = origin
merge = refs/heads/master
and it creates a file here .git/refs/remotes/origin/master
, representing the remote branch.
These settings are local to the current repository, so they will not apply to other repositories.
The changes in .git/config
are permanent (until you explicitly change them), so the effects of git push -u
are permanent.
git push -u
tells git to track the remote branch locally (an 'upstream tracking reference'), so git push
whilst on the local branch will then always push to the remote branch specified in the initial git push -u
. This will persist on the branch (or master in your case) until the next push -u
you do (which will cause it to track another remote branch).
It's also used so that other git commands know where to retrieve data from e.g. git pull
uses it to pull changes made to the remote being tracked to the local repo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With