如何创建git远程跟踪分支

时间:2019-03-23 03:18:46

标签: git github git-branch git-remote

They said就这么简单

  

您可以通过将-u标志与“ git push”一起使用,告诉Git跟踪新创建的远程分支。

但这对我没用。

如何创建git Remote-Tracking分支,

  

Git现在可以通知您有关“未推动”和“未推动”的提交。

这是我的:

$ git status 
On branch newfeature/v4-json
nothing to commit, working tree clean

vs我期望的,引用above article

$ git status
# On branch dev
# Your branch and 'origin/dev' have diverged,
# and have 1 and 2 different commits each, respectively.
#
nothing to commit (working directory clean)

即,有关“未推动”和“未推动”提交的信息。
即,我希望看到与以下内容相同:

$ git status
On branch master
Your branch is ahead of 'origin/master' by 3 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

但是,从上面的实际输出中,您可以看到,尽管我已经进行了几次提交,但我仍然无法看到到目前为止我已经进行了多少次提交。

这就是我所做的:

$ git push -u origin newfeature/v4-json
Counting objects: 12, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (11/11), done.
Writing objects: 100% (12/12), 1.87 KiB | 958.00 KiB/s, done.
Total 12 (delta 9), reused 0 (delta 0)
remote: Resolving deltas: 100% (9/9), completed with 9 local objects.
remote: 
remote: Create a pull request for 'newfeature/v4-json' on GitHub by visiting:
remote:      https://github.com/.../pull/new/newfeature/v4-json
remote: 
To github.com:xxx/yyy.git
 * [new branch]      newfeature/v4-json -> newfeature/v4-json
Branch 'newfeature/v4-json' set up to track remote branch 'newfeature/v4-json' from 'origin' by rebasing.

但是我没有git从'origin'设置的远程跟踪分支'newfeature / v4-json':

A)git remote show origin根本不显示我的新功能的远程跟踪分支:

$ git remote show origin
* remote origin
  Fetch URL: git@github.com:go-easygen/easygen.git
  Push  URL: git@github.com:go-easygen/easygen.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branches configured for 'git pull':
    master             rebases onto remote master
    newfeature/v4-json rebases onto remote newfeature/v4-json
  Local refs configured for 'git push':
    master             pushes to master             (up to date)
    newfeature/v4-json pushes to newfeature/v4-json (up to date)

根据http://www.gitguys.com/topics/adding-and-removing-remote-branches

,以下是我想看到的
$ git remote show origin
* remote origin
  Fetch URL: /tmp/.../git/rp0
  Push  URL: /tmp/.../git/rp0
  HEAD branch: master
  Remote branches:
    master     tracked
    newfeature tracked
  Local branches configured for 'git pull':
    master     rebases onto remote master
    newfeature rebases onto remote newfeature
  Local refs configured for 'git push':
    master     pushes to master     (up to date)
    newfeature pushes to newfeature (up to date)

Remote branches:部分中,请注意,除了master tracked,还有一个newfeature tracked。根据上述文章,该newfeature tracked被称为远程跟踪分支

B)git branch -a都不是:

$ git branch -a
  master
* newfeature/v4-json
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

那里只有一个remotes/origin/master远程跟踪名称,而我希望更多。例如。 (无关紧要,只是为了显示具有更多远程跟踪名称的情况),

$ git branch -a
* master
  remotes/origin/HEAD
  remotes/origin/master
  remotes/origin/v1.0-stable
  remotes/origin/experimental

C)git branch -vv也不是:

$ git branch -vv
  master             75369c3 [origin/master] - [*] allow ...
* newfeature/v4-json 8c98d9c - [*] update ...

我希望看到,

$ git branch -vv
  master             75369c3 [origin/master] - [*] allow ...
* newfeature/v4-json 8c98d9c [origin/newfeature/v4-json] - [*] update ...

此外,

git pull也不从远程更新我的 local 分支:

$ git pull
From github.com:xxx/yyy
 * branch            newfeature/v4-json -> FETCH_HEAD
Already up to date.
Current branch newfeature/v4-json is up to date.

$ git pull
From github.com:xxx/yyy
 * branch            newfeature/v4-json -> FETCH_HEAD
Already up to date.
Current branch newfeature/v4-json is up to date.

$ git pull
From github.com:xxx/yyy
 * branch            newfeature/v4-json -> FETCH_HEAD
Already up to date.
Current branch newfeature/v4-json is up to date.

也就是说,无论我拉多少次,我都不会得到与

相同的输出
$ git pull
Already up to date.
Current branch master is up to date.

以上所有都是 不是 。我已经使用MS VS多次创建了Remote-Tracking Branch,其结果完全符合我的预期,而不是上面的预期。但是,我不喜欢黑魔术,所以我想知道如何用普通的git来做同样的事情。

那么创建git Remote-Tracking Branch的正确方法是什么?

0 个答案:

没有答案