yxixi 发表于 2018-1-16 07:21:13

技术生活杂烩-迟到的博客

一。使用场景: 本地新建一个分支后,必须要做远程分支关联。如果没有关联,git会在下面的操作中提示你显示的添加关联。关联目的是如果在本地分支下操作: git pull, git push ,不需要指定在命令行指定远程的分支.  I create a new branch in Git:
  git branch my_branch
  Push it:
  git push origin my_branch
  Now say someone made some changes on the server and I want to pull from origin/my_branch. I do:
  git pull
  But I get:
  You asked me to pull without telling me which branch you
  want to merge with, and 'branch.my_branch.merge' in
  your configuration file does not tell me, either. Please
  specify which branch you want to use on the command line and
  try again (e.g. 'git pull <repository> <refspec>').
  See git-pull(1) for details.
  If you often merge with the same branch, you may want to
  use something like the following in your configuration file:

  remote = <nickname>
  merge = <remote-ref>

  url = <url>
  fetch = <refspec>
  See git-config(1) for details.
  I learned that I can make it work with:
  git branch --set-upstream my_branch origin/my_branch
  注意,推送到远程分支后,默认也不是跟踪snsconnct:mater分支,你只要没有显示指定,git pull的时候,就会提示你。
  二。替代:
  该语法等价与在第一次提交分支时,使用git push -u origin my_branch:
  一种更简单的方式用来取代不好忘记的 git branch --set-upstream 是git push -u origin my_branch
  在你第一次提交你的分支的时候使用。它会像git branch --set-upstream一样在本地分支与远程分去建立联系。
  通常我们在新建分支的时候,一定要显式建立这种联系。
  三。类似
  thisbe equivalent to what is automatically done when you initially clone a repository
  附:
  下面部分就是git clone之后,添加到文件里的内容。感觉git clone主要是cline仓库。用来初始化。所以,它不能取代--set-upstream.

  repositoryformatversion = 0
  filemode = true
  logallrefupdates = true
  autocrlf = false
  bare = false

  url = ssh://root@hostname/path
  fetch = +refs/heads/*:refs/remotes/origin/*

  remote = origin
  merge = refs/heads/sns
  或者
  # git remote add origin ssh://...
  now configure master to know to track
  # git config branch.master.remote origin
  # git config branch.master.merge refs/heads/master
  and push
  # git push origin master
  四。命令的最终修改都是针对config文件。
  使用--set-upstream去跟踪远程分支。
  config在命令执行之前:

  repositoryformatversion = 0
  filemode = true
  bare = false
  logallrefupdates = true
  ignorecase = true

  fetch = +refs/heads/*:refs/remotes/origin/*
  url = root@****************

  remote = origin
  merge = refs/heads/master

  url = root@app220:/*******************
  fetch = +refs/heads/*:refs/remotes/snsconnect/*
  执行之后:

  remote = snsconnect
  merge = refs/heads/sns
页: [1]
查看完整版本: 技术生活杂烩-迟到的博客