Git - 新分支和远程跟踪(为 push/pull 配置 origin/master)

Git - new branch and remote tracking (configure for push/pull with origin/master)

Track Remote Branch 是做什么的?另外configure for push/pull with origin/master是什么意思?

这是来自 git 的文档:

A 'tracking branch' in Git is a local branch that is connected to a remote branch. When you push and pull on that branch, it automatically pushes and pulls to the remote branch that it is connected with.

Use this if you always pull from the same upstream branch into the new branch, and if you don't want to use "git pull" explicitly.

如果您跟踪本地分支到远程分支,即 feature1 跟踪 origin/feature1 并且 master 也是如此,那么您就安全了!

编辑:这是一本很棒的 explanation ProGit 书。基本上:

Tracking branches are local branches that have a direct relationship to a remote branch. If you’re on a tracking branch and type git pull, Git automatically knows which server to fetch from and which branch to merge in.

跟踪远程分支意味着您希望自动将正在跟踪的远程分支的更改合并到本地分支。 default behavior of git push 仅当本地名称和远程名称相同时才将更改推送到已配置的上游。在您的情况下,您不会通过推送到 feature1.

来修改 origin/master

对于与他人协作的功能分支,您通常希望跟踪 origin/feature1 而不是 origin/master。如果您单独处理一项功能,您可能根本不想设置跟踪。

git branch documentation 描述了设置跟踪的幕后情况。

When creating a new branch, set up branch.<name>.remote and branch.<name>.merge configuration entries to mark the start-point branch as "upstream" from the new branch. This configuration will tell git to show the relationship between the two branches in git status and git branch -v. Furthermore, it directs git pull without arguments to pull from the upstream when the new branch is checked out.

同一部分继续

This behavior is the default when the start point is a remote-tracking branch.

远程跟踪分支(或简称为跟踪分支)的名称形式为 remote/branch-name。 git 存储库通常有一个名为 master 的分支,因此克隆几乎总是有一个本地 master 分支和一个名为 origin/master 的跟踪分支。将 origin/master 视为在您最近的 git pullgit fetch 时标记 master 分支在您的 origin 遥控器上的历史点。 =34=]