learning Git: tracking vs. setting upstream (-u) for remotes?

后端 未结 3 1799
清歌不尽
清歌不尽 2021-02-05 12:45

I am learning Git and am attempting to understand the difference between \"tracking\" a remote and defining an \"upstream\" relationship with it (with the -u tag).

3条回答
  •  故里飘歌
    2021-02-05 13:10

    "Tracking" and "upstream" are related terms. "Tracking" means associating a branch of your local repository with an upstream branch, i.e. a branch that lives in a remote repository. For instance,

    git push -u origin newbranch
    

    sets up the tracking information of your local newbranch so that the newbranch that lives in the remote repo called origin (i.e. the remote repo that your local repo knows under the nickname origin) is considered the upstream branch of your local newbranch... and carries out the push.

    If you obtained your local repository by cloning it, you don't need to run

    git push -u origin master
    

    because origin/master is already set up as master's upstream branch. In other words, master is already set to track origin/master.

提交回复
热议问题