前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >远程仓库的使用

远程仓库的使用

作者头像
dogfei
发布2020-07-31 10:52:40
3630
发布2020-07-31 10:52:40
举报
文章被收录于专栏:devops探索devops探索

远程仓库是指托管在网络上的项目仓库,可能会有好多个,其中有些你只能读,另外有些可以写。同他人协作开发某个项目时,需要管理这些远程仓库,以便推送或拉取数据,分享各自的工作进展。 管理远程仓库的工作,包括添加远程库,移除废弃的远程库,管理各式远程库分支,定义是否跟踪这些分支,等等

命令介绍

1、查看当前有哪些远程仓库

<code>git remote</code>








<code># git remote</code>



origin

在克隆完某个项目后,git默认会以origin这个名字来标识所克隆的远程仓库

2、显示对应的远程仓库地址

<code>git remote -v</code>








<code># git remote -v</code>



origin  <a href="git://github.com/schacon/ticgit.git">git://github.com/schacon/ticgit.git</a> (fetch)



origin  <a href="git://github.com/schacon/ticgit.git">git://github.com/schacon/ticgit.git</a> (push)

3、添加远程仓库

git remote add

git remote add pb <a href="git://github.com/paulboone/ticgit.git">git://github.com/paulboone/ticgit.git</a>

查看

<code># git remote -v</code>



origin  <a href="git://github.com/schacon/ticgit.git">git://github.com/schacon/ticgit.git</a> (fetch)



origin  <a href="git://github.com/schacon/ticgit.git">git://github.com/schacon/ticgit.git</a> (push)



pb      <a href="git://github.com/paulboone/ticgit.git">git://github.com/paulboone/ticgit.git</a> (fetch)



pb      <a href="git://github.com/paulboone/ticgit.git">git://github.com/paulboone/ticgit.git</a> (push)

4、从远程仓库抓取文件

<code>git fetch </code>

这里我们新增了一个pb仓库

<code># git fetch pb</code>



remote: Counting objects: 43, done.



remote: Total 43 (delta 22), reused 22 (delta 22), pack-reused 21



Unpacking objects: 100% (43/43), done.



From <a href="git://github.com/paulboone/ticgit">git://github.com/paulboone/ticgit</a>



* [new branch]      master     -> pb/master



* [new branch]      ticgit     -> pb/ticgit

这条命令会到远程仓库拉取本地没有,而远程仓库有的信息到本地,拉取后的内容只是放到本地仓库,并不会自动合并到当前工作分支,需要手动合并分支

5、查看远程仓库信息

<code>git remote show</code>

例如

<code># git remote show origin</code>



* remote origin



  Fetch URL: <a href="git://github.com/schacon/ticgit.git">git://github.com/schacon/ticgit.git</a>



  Push  URL: <a href="git://github.com/schacon/ticgit.git">git://github.com/schacon/ticgit.git</a>



  HEAD branch: master



  Remote branches:



    master tracked



    ticgit tracked



  Local branch configured for &#8216;git pull&#8217;:



    master merges with remote master



  Local ref configured for &#8216;git push&#8217;:



    master pushes to master (up to date)

6、远程仓库的删除和重命名

<code>git remote rename</code>

例如

<code># git remote rename pb chenfei</code>

删除

<code>git remote rm</code>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-09-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档