git remote 用法
来源:互联网 发布:淘宝免费打单软件 编辑:程序博客网 时间:2024/05/17 04:13
在博客园里看见一篇老好的文章,教我们做笔记啦,但是做完笔记还是要记得总结哦!
来吧,让我们一起来总结吧,今天先来看看git远程的仓库是怎么建立的。
当然,使用git嘛,第一步肯定是得新建一个git仓库,总得有个操作的空间吧,巧妇难为无米之炊嘛。
1.初始化一个空的git仓库
1 software@debian:~$ mkdir yafeng2 software@debian:~$ cd yafeng/3 software@debian:~/yafeng$ ls4 software@debian:~/yafeng$ git init5 Initialized empty Git repository in /home/software/yafeng/.git/6 software@debian:~/yafeng$
命令注释:
在上面的命令中,真正去初始化的是第四行的那句---git init
当然,还有很多同学会看见加了参数--bare的命令,这个命令会在我们以后慢慢给大家解释,对于不是作为共享仓库,而是作为一个自己操作的仓库,上面这样就足够了。
好了,现在yafeng目录就是我们的据点---git仓库了哦。
下面我们总要做点什么的吧,入宝山总不能光看着哦:
2.向仓库提交我们写的文件
1 software@debian:~/yafeng$ echo "our first git repository" >> file2 software@debian:~/yafeng$ ls3 file4 software@debian:~/yafeng$ git add file5 software@debian:~/yafeng$ git commit -m "the first file to commit" file6 [master (root-commit) 0c72641] the first file to commit7 1 files changed, 1 insertions(+), 0 deletions(-)8 create mode 100644 file9 software@debian:~/yafeng$
命令解释:
我们在仓库中新建了一个文件file,作为我们的示例文件。
第4行:将file文件的信息添加到git仓库的索引库中,并没有真正添加到库。当然上例中的file文件只是我们的示例,它是一个路径,因此,可以是文件,更可以是目录。
第5行:将索引库中的内容向git仓库进行提交。这步之后文件file才算真正提交到拉git仓库中。双引号中的内容是根据每次修改的不同内容,由我们自己去填写的,
很多人会看见
git commit -a -m “ ”
这条的命令是在你已经add了一个或多个文件过之后,然后修改了这些文件,就可以使用该命令进行提交。
好了,不管怎么样,终于是将文件提交到库了。可是现在的仓库只是一个本地的仓库,我们的目标是变成远程仓库哦,继续吧。
3.在本地仓库添加一个远程仓库,并将本地的master分支跟踪到远程分支
1 software@debian:~/yafeng$ git remote add origin ssh://software@172.16.0.30/~/yafeng/.git2 software@debian:~/yafeng$ git push origin master3 software@172.16.0.30's password: 4 Everything up-to-date5 software@debian:~/yafeng$
命令注释:
第1行:在本地仓库添加一个远程仓库,当然ssh后面的地址是我们本地仓库的地址.
第2行:将本地master分支跟踪到远程分支,在git仓库建立之初就会有一个默认的master分支,当然你如果建立了其他分支,也可以用同样的方法去跟踪.
对于分支的事情,我们会在以后细细的讲述.
做到拉这一步了吗?我告诉你,你已经完成目的了哦,现在的git仓库已经是一个远程仓库了,
不相信吗?我们来测试一次阿:
4.测试
现在本机上看看:
1 software@debian:~/yafeng$ git remote show origin 2 software@172.16.0.30's password: 3 * remote origin 4 Fetch URL: ssh://software@172.16.0.30/~/yafeng/.git 5 Push URL: ssh://software@172.16.0.30/~/yafeng/.git 6 HEAD branch: master 7 Remote branch: 8 master tracked 9 Local ref configured for 'git push':10 master pushes to master (up to date)11 software@debian:~/yafeng$
代码注释:
第1行:显示远程信息
很多看见这还是会不以为然的,这又能说明什么呢?好,那就来点实际的:
在另一个机子上,远程clone
1 root@yafeng-VirtualBox:~# ls 2 bin gittest read_temp 3 root@yafeng-VirtualBox:~# git clone ssh://software@172.16.0.30/~/yafeng/.git 4 Cloning into yafeng... 5 software@172.16.0.30's password: 6 remote: Counting objects: 9, done. 7 remote: Compressing objects: 100% (3/3), done. 8 remote: Total 9 (delta 0), reused 0 (delta 0) 9 Receiving objects: 100% (9/9), done.10 root@yafeng-VirtualBox:~# ls11 bin gittest read_temp yafeng12 root@yafeng-VirtualBox:~# cd yafeng/13 root@yafeng-VirtualBox:~/yafeng# ls14 file15 root@yafeng-VirtualBox:~/yafeng#
代码注释:
第3行:就是远程clone仓库.很明显的对比可以知道多了yafeng目录,而这个yafeng目录里的内容和我们另外一台机子上的内容一样
至此,一个简单的git远程仓库就建好了,简单不,试试吧!!
- git remote用法总结
- git remote用法总结
- git remote 用法
- git remote常见用法
- git命令之git remote的用法
- git命令之git remote的用法
- git命令之git remote的用法
- git命令之git remote的用法
- git命令之git remote的用法详解
- git remote
- git remote
- git remote
- git remote
- git remote
- git remote
- git remote
- git remote
- git remote
- LPC1778 U盘进行bootloader
- android 应用开发
- 我的心太乱
- Android开发随记(3)-- ActionBar控件显示、Checkbox样式
- 搭建高可用mongodb集群(四)—— 分片
- git remote 用法
- 题目:数字逆序且求各个位数乘积
- 解释器模式 Interpreter Pattern
- C++ 异常处理(四) 有关异常处理的注意事项
- Java基础---集合 (黑马程序员)
- eclipse安装AmaterasUML插件(LUNA)
- windows脚本-CMD和Batch
- 2015微软技术俱乐部科技文化月 —— “第七届SeedCoder编程大赛”火热报名中!!!
- 查看分区UUID