git学习笔记整理-6-远程仓库

来源:互联网 发布:项目管理平台软件 编辑:程序博客网 时间:2024/05/17 09:31

运行 git remote 命令,它会列出你指定的每一个远程服务器的简写



指定选项 -v,会显示需要读写远程仓库使用的 Git 保存的简写与其对应的 URL。

$ git remote -voriginhttps://github.com/schacon/ticgit (fetch)originhttps://github.com/schacon/ticgit (push)

如果有多个,会显示多个,根据不同的协议连接的也会一次显示出来;

添加一个远程仓库:

$ git remote add pb https://github.com/paulboone/ticgit

$ git remote add <shortname> <url>


再次输入$ git remote -v

输出:

originhttps://github.com/schacon/ticgit (fetch)originhttps://github.com/schacon/ticgit (push)pbhttps://github.com/paulboone/ticgit (fetch)pbhttps://github.com/paulboone/ticgit (push)

就像上面显示:已经成功添加;


设置的短名可以代替整个url。

如果你想拉取 Paul 的仓库中有但你没有的信息,可以运行 git fetch pb

$ git fetch pbremote: Counting objects: 43, done.remote: Compressing objects: 100% (36/36), done.remote: Total 43 (delta 10), reused 31 (delta 5)Unpacking objects: 100% (43/43), done.From https://github.com/paulboone/ticgit * [new branch]      master     -> pb/master * [new branch]      ticgit     -> pb/ticgit

$ git clone 克隆了整个仓库以后,命令会自动将其添加为远程仓库并默认以 “origin” 为简写; 

所以,git fetch origin 会抓取克隆(或上一次抓取)后新推送的所有工作

注意:

git fetch 命令会将数据拉取到你的本地仓库 - 它并不会自动合并或修改你当前的工作,你必须手动将其合并入你的工作。


发布推送到服务器:

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

$ git push origin master

只有当你有所克隆服务器的写入权限,并且之前没有人推送过时,这条命令才能生效。 当你和其他人在同一时间克隆,他们先推送到上游然后你再推送到上游,你的推送就会毫无疑问地被拒绝。 你必须先将他们的工作拉取下来并将其合并进你的工作后才能推送。


查看远程仓库:

git remote show [remote-name] 

$ git remote show origin


它同样会列出远程仓库的 URL 与跟踪分支的信息。 这些信息非常有用,它告诉你正处于 master 分支,并且如果运行 git pull,就会抓取所有的远程引用,然后将远程 master 分支合并到本地 master 分支。 它也会列出拉取到的所有远程引用。


远程仓库的移除与重命名:

$ git remote rename pb(old) paul(new)


$ git remote rm paul 这个命令可移除

原创粉丝点击