git基础之远程仓库的使用

远程仓库的使用

远程仓库是指托管在因特网或其他网络中的你的项目的版本库。(词语“远程”未必表示仓库在网络或互联网上的其它位置,而只是表示它在别处。)

git remote / git remote -v 查看远程仓库

通常通过命令 git clone 克隆一个远程仓库的时候,会给这个仓库默认一个名称 origin

$ git clone https://github.com/schacon/ticgit
Cloning into 'ticgit'...
remote: Reusing existing pack: 1857, done.
remote: Total 1857 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (1857/1857), 374.35 KiB | 268.00 KiB/s, done.
Resolving deltas: 100% (772/772), done.
Checking connectivity... done.
$ cd ticgit
$ git remote
origin

指定 -v 可以查看完整路径

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

git remote add <shortname> <url> 添加远程仓库

运行 git remote add 添加一个新的远程 Git 仓库,同时指定一个方便
使用的简写:

$ git remote
origin
$ git remote add pb https://github.com/paulboone/ticgit
$ git remote -v
origin https://github.com/schacon/ticgit (fetch)
origin https://github.com/schacon/ticgit (push)
pb https://github.com/paulboone/ticgit (fetch)
pb https://github.com/paulboone/ticgit (push)

git fetch 从远程仓库拉取

git fetch 会访问远程仓库,拉取所有你还没有的数据。

如果你的当前分支设置了跟踪远程分支, 那么可以用 git pull 命令来自动抓取后合并该远程分支到当前分支。git clone 命令会自动设置本地 master 分支跟踪克隆的远程仓库的 master 分支(或其它名字的默认分支)。

git push 推送到远程仓库

当你想要将 master 分支推送到 origin 服务器时, 那么运行这个命令就可以将你所做的备份到服务器:

$ git push origin master

注意:你需要有远程仓库所在服务器的写入权限,在推送之前,你需要先拉取其他贡献者做出的修改。

git remote show <remote> 查看某个远程仓库

$ git remote show origin
* remote origin
  Fetch URL: https://github.com/schacon/ticgit
  Push URL: https://github.com/schacon/ticgit
  HEAD branch: master
  Remote branches:
  master tracked
  dev-branch tracked
  Local branch configured for 'git pull':
  master merges with remote master
  Local ref configured for 'git push':
  master pushes to master (up to date)

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

远程仓库的重命名与移除

git remote rename 重命名一个远程仓库

$ git remote rename pb paul
$ git remote
origin
paul

git remote remote 或者 git remote rm移除一个远程仓库

$ git remote remove paul
$ git remote
origin
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值