查看远程仓库
#首先先进入目录哦
$ git remote -v
#-v, 显示url
#例子
$ cd grit
$ git remote -v
bakkdoor <https://github.com/bakkdoor/grit> (fetch)
bakkdoor <https://github.com/bakkdoor/grit> (push)
cho45 <https://github.com/cho45/grit> (fetch)
cho45 <https://github.com/cho45/grit> (push)
defunkt <https://github.com/defunkt/grit> (fetch)
defunkt <https://github.com/defunkt/grit> (push)
koke git://github.com/koke/grit.git (fetch)
koke git://github.com/koke/grit.git (push)
origin git@github.com:mojombo/grit.git (fetch) #clone 的仓库, 自动叫origin
origin git@github.com:mojombo/grit.git (push)
# 第一列是URL 的代称, 再次用到这个仓库的时候可以用代称代替URL
# 第三列括号里的内容是说, 这个远程仓库你拉取数据的url 和push 数据的url
# 一个仓库可以对应N 个远程仓库
#查看某一个远程仓库
#git remote show [remote-name]
$ git remote show origin
* remote origin
# 远程仓库的代称
URL: <https://github.com/my-org/complex-project>
# 远程仓库的地址
Fetch URL: <https://github.com/my-org/complex-project>
# 又来一遍???
Push URL: <https://github.com/my-org/complex-project>
# 又来一遍??? 拉去数据和push 数据时可能会有不同的url ???
HEAD branch: master
# 本地仓库当前坐在分支
Remote branches:
# 远程仓库的分支信息
# 哪些在本地没有, 哪些已经移除
master tracked
dev-branch tracked
markdown-strip tracked
issue-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':
# 如果pull, 哪些分支会自动合并
dev-branch merges with remote dev-branch
master merges with remote master
Local refs configured for 'git push':
# 如果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)
添加远程仓库
#git remote add <shortname> <url>
$ git remote add pb <https://github.com/paulboone/ticgit>
#只拉取没有的内容
$ git fetch pb
#fetch 美: [fetʃ 拿来 拿取
#pb 代称, 算是url 的别名
#拉取的内容成为本地仓库的分支, 通过pb/master 访问
#并不会自动合并, 不影响自己仓库的状态
#一般会从clone 的那个服务器上用git pull 拉去更新的数据并自动合并
推送到远程仓库
#git push [remote-name] [branch-name]
$ git push origin master
#推送时如果服务器已经有更新内容, 必须先拉去更新的内容, 合并后再push
删除或重命名远程仓库
#重命名
$ git remote rename pb paul
#删除
$ git remote rm paul