1 远程仓库

链接

1.1 查看 git remote

默认为 origin(如果你使用 clone 命令克隆了一个仓库,命令会自动将其添加为远程仓库并默认以 “origin” 为简写)
你也可以指定选项 -v,会显示需要读写远程仓库使用的 Git 保存的简写与其对应的 URL。

  1. $ git remote -v
  2. origin https://github.com/schacon/ticgit (fetch)
  3. origin https://github.com/schacon/ticgit (push)

1.2 添加远程仓库

git remote add

1.3 从远程仓库中抓取与拉取

git fetch [remote-name]
必须注意 git fetch 命令会将数据拉取到你的本地仓库 - 它并不会自动合并或修改你当前的工作。 当准备好时你必须手动将其合并入你的工作。

运行 git pull 通常会从最初克隆的服务器上抓取数据并自动尝试合并到当前所在的分支。

1.4推送到远程仓库

git push [remote-name] [branch-name]

1.5查看远程仓库

git remote show [remote-name]

  1. $ git remote show origin
  2. * remote origin
  3. Fetch URL: https://github.com/schacon/ticgit
  4. Push URL: https://github.com/schacon/ticgit
  5. HEAD branch: master
  6. Remote branches:
  7. master tracked
  8. dev-branch tracked
  9. Local branch configured for 'git pull':
  10. master merges with remote master
  11. Local ref configured for 'git push':
  12. master pushes to master (up to date)

这个命令列出了当你在特定的分支上执行 git push 会自动地推送到哪一个远程分支。 它也同样地列出了哪些远程分支不在你的本地,哪些远程分支已经从服务器上移除了,还有当你执行 git pull 时哪些分支会自动合并。

  1. $ git remote show origin
  2. * remote origin
  3. URL: https://github.com/my-org/complex-project
  4. Fetch URL: https://github.com/my-org/complex-project
  5. Push URL: https://github.com/my-org/complex-project
  6. HEAD branch: master
  7. Remote branches:
  8. master tracked
  9. dev-branch tracked
  10. markdown-strip tracked
  11. issue-43 new (next fetch will store in remotes/origin)
  12. issue-45 new (next fetch will store in remotes/origin)
  13. refs/remotes/origin/issue-11 stale (use 'git remote prune' to remove)
  14. Local branches configured for 'git pull':
  15. dev-branch merges with remote dev-branch
  16. master merges with remote master
  17. Local refs configured for 'git push':
  18. dev-branch pushes to dev-branch (up to date)
  19. markdown-strip pushes to markdown-strip (up to date)
  20. master pushes to master (up to date)