1 远程仓库
1.1 查看 git remote
默认为 origin(如果你使用 clone 命令克隆了一个仓库,命令会自动将其添加为远程仓库并默认以 “origin” 为简写)
你也可以指定选项 -v,会显示需要读写远程仓库使用的 Git 保存的简写与其对应的 URL。
$ git remote -vorigin https://github.com/schacon/ticgit (fetch)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]
$ git remote show origin* remote originFetch URL: https://github.com/schacon/ticgitPush URL: https://github.com/schacon/ticgitHEAD branch: masterRemote branches:master trackeddev-branch trackedLocal branch configured for 'git pull':master merges with remote masterLocal ref configured for 'git push':master pushes to master (up to date)
这个命令列出了当你在特定的分支上执行 git push 会自动地推送到哪一个远程分支。 它也同样地列出了哪些远程分支不在你的本地,哪些远程分支已经从服务器上移除了,还有当你执行 git pull 时哪些分支会自动合并。
$ git remote show origin* remote originURL: https://github.com/my-org/complex-projectFetch URL: https://github.com/my-org/complex-projectPush URL: https://github.com/my-org/complex-projectHEAD branch: masterRemote branches:master trackeddev-branch trackedmarkdown-strip trackedissue-43 new (next fetch will store in remotes/origin)issue-45 new (next fetch will store in remotes/origin)refs/remotes/origin/issue-11 stale (use 'git remote prune' to remove)Local branches configured for 'git pull':dev-branch merges with remote dev-branchmaster merges with remote masterLocal refs configured for 'git push':dev-branch pushes to dev-branch (up to date)markdown-strip pushes to markdown-strip (up to date)master pushes to master (up to date)
