1、查看远程仓库
$ git remote
你也可以指定选项 -v
,会显示需要读写远程仓库使用的 Git 保存的简写与其对应的 URL。
$ git remote -v
origin https://github.com/schacon/ticgit (fetch)
origin https://github.com/schacon/ticgit (push)
2、添加远程仓库
运行 git remote add <shortname> <url>
添加一个新的远程 Git 仓库
$ git remote add pb https://github.com/paulboone/ticgit
现在你可以在命令行中使用字符串 pb
来代替整个 URL。 例如,如果你想拉取 Paul 的仓库中有但你没有的信息,可以运行 git fetch pb
:
$ git fetch pb
3、从远程仓库中抓取与拉取
$ git fetch [remote-name]
这个命令会访问远程仓库,从中拉取所有你还没有的数据。 执行完成后,你将会拥有那个远程仓库中所有分支的引用,可以随时合并或查看。
必须注意 git fetch
命令会将数据拉取到你的本地仓库 - 它并不会自动合并或修改你当前的工作。 当准备好时你必须手动将其合并入你的工作。
4、推送到远程仓库
git push [remote-name] [branch-name]
$ git push origin master
5、查看远程仓库
$ git remote show origin
6、远程仓库的移除与重命名
$ git remote rename pb paul
$ git remote
origin
paul
$ git remote rm paul
$ git remote
origin