Linux下使用github教程
来源:互联网 发布:自制相册软件下载 编辑:程序博客网 时间:2024/05/22 12:53
1. Git是什么?
Git是一个分布式版本控制/软件配置管理软件,原是Linux内核开发者Linus Torvalds为更好地管理Linux内核开发而设计。
相比CVS/SVN,Git 的优势:
- 支持离线开发,离线Repository
- 强大的分支功能,适合多个独立开发者协作
- 速度块
2.GITHUB是什么?
GitHub 是一个共享虚拟主机服务,用于存放使用Git版本控制的软件代码和内容项目。
3.Linux虚拟机上使用git和github
3.1 注册github账号
此步骤比较简单,无需赘述。
3.2 虚拟机安装git客户端
我使用的是CentOS虚拟机,安装命令如下:
- yum install git git-gui
yum install git git-gui3.3 生成秘钥对,这样项目可以push到github上
- [root@CentOS tuzhutuzhu]# ssh-keygen -t rsa -C “*****@**.com”
- Generating public/private rsa key pair.
- Enter file in which to save the key (/root/.ssh/id_rsa):
- Enter passphrase (empty for no passphrase):
- Enter same passphrase again:
- Your identification has been saved in /root/.ssh/id_rsa.
- Your public key has been saved in /root/.ssh/id_rsa.pub.
- The key fingerprint is:
- 63:68:68:ad:23:0f:8f:85:4a:cc:67:60:47:9e:7a:fa 15895214140@126.com
- The key’s randomart image is:
- +–[ RSA 2048]—-+
- | |
- | |
- | . |
- | o .o . |
- | o +o + S |
- |+ +o o . . |
- | =+++ |
- |..=B . |
- |..oEo |
- +—————–+
- [root@CentOS tuzhutuzhu]#
[root@CentOS tuzhutuzhu]# ssh-keygen -t rsa -C "*****@**.com"Generating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa.Your public key has been saved in /root/.ssh/id_rsa.pub.The key fingerprint is:63:68:68:ad:23:0f:8f:85:4a:cc:67:60:47:9e:7a:fa 15895214140@126.comThe key's randomart image is:+--[ RSA 2048]----+| || || . || o .o . || o +o + S ||+ +o o . . || =+++ ||..=B . ||..oEo |+-----------------+[root@CentOS tuzhutuzhu]#3.4 将.ssh/id_rsa.oub拷贝到GitHub
3.5 测试是否能连接到GitHub
- [root@CentOS tuzhutuzhu]# ssh git@github.com
- The authenticity of host ’github.com (192.30.252.131)’ can’t be established.
- RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
- Are you sure you want to continue connecting (yes/no)? yes
- Warning: Permanently added ’github.com,192.30.252.131’ (RSA) to the list of known hosts.
- Enter passphrase for key ‘/root/.ssh/id_rsa’:
- Permission denied (publickey).
- [root@CentOS tuzhutuzhu]#
[root@CentOS tuzhutuzhu]# ssh git@github.comThe authenticity of host 'github.com (192.30.252.131)' can't be established.RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added 'github.com,192.30.252.131' (RSA) to the list of known hosts.Enter passphrase for key '/root/.ssh/id_rsa': Permission denied (publickey).[root@CentOS tuzhutuzhu]#3.6 设置Git全局用户配置
- # git config –global user.name “Firstname Lastname”
- # git config –global user.email “your_email@youremail.com”
- 此处用户名为自己的实际姓名(自定义的),而非登录用户名
# git config --global user.name "Firstname Lastname"
创建完成:
3.8 创建本地新项目仓库,此步骤可按照上图GitHub中仓库创建完成后网页上的提示执行
- # mkdir new-project(*1)
- # cd new-project
- # git init
- # touch README
- # git add README
- # git commit -m ‘first commit’
- 定义远程服务器别名origin
- # git remote add origin git@github.com:***/new-project.git(*2)
- 本地和远程合并,本地默认分支为master
- # git push origin master
# mkdir new-project(*1)# cd new-project# git init# touch README# git add README# git commit -m 'first commit'定义远程服务器别名origin# git remote add origin git@github.com:***/new-project.git(*2) 本地和远程合并,本地默认分支为master# git push origin master (*1) 此处的仓库名必须与3.7中在GitHub中创建的仓库名相同
(*2) 此处***就是GitHub的用户名
在执行push操作时,可能会出现如下错误:
- [root@CentOS vmware]# git push -u origin master
- error: The requested URL returned error: 403 while accessing https://github.com/tuzhutuzhu/vmware.git/info/refs
- fatal: HTTP request failed
[root@CentOS vmware]# git push -u origin mastererror: The requested URL returned error: 403 while accessing https://github.com/tuzhutuzhu/vmware.git/info/refsfatal: HTTP request failed这是因为GitHub好像只支持ssh的方式访问仓库。解决方法如下:
- 1).vim .git/config
- 2).将[remote ”origin”]部分的url按照如下格式设置:
- url = ssh://git@github.com/tuzhutuzhu/vmware.git
- fetch = +refs/heads/*:refs/remotes/origin/*
1).vim .git/config2).将[remote "origin"]部分的url按照如下格式设置: url = ssh://git@github.com/tuzhutuzhu/vmware.git fetch = +refs/heads/*:refs/remotes/origin/*再次执行push操作,结果如下:
[root@CentOS vmware]# git push -u origin master
- Enter passphrase for key ‘/root/.ssh/id_rsa’:
- Counting objects: 7, done.
- Delta compression using up to 2 threads.
- Compressing objects: 100% (3/3), done.
- Writing objects: 100% (7/7), 548 bytes, done.
- Total 7 (delta 0), reused 0 (delta 0)
- To ssh://git@github.com/tuzhutuzhu/vmware.git
- * [new branch] master -> master
- Branch master set up to track remote branch master from origin.
- [root@CentOS vmware]#
Enter passphrase for key '/root/.ssh/id_rsa': Counting objects: 7, done.Delta compression using up to 2 threads.Compressing objects: 100% (3/3), done.Writing objects: 100% (7/7), 548 bytes, done.Total 7 (delta 0), reused 0 (delta 0)To ssh://git@github.com/tuzhutuzhu/vmware.git * [new branch] master -> masterBranch master set up to track remote branch master from origin.[root@CentOS vmware]#
这样,就将文件上传到GitHub上了。
还有另外一种解决方法,将url做如下变更:
原:url = https:github.com/tuzhutuzhu/helloworld.git
现:url = https://tuzhutuzhu@github.com/tuzhutuzhu/helloworld.git
有关git的详细操作,可以参考如下:
http://download.csdn.net/detail/tuzhutuzhu/6966853
阅读全文
0 0
- Linux下使用github教程
- Linux下 GitHub使用
- linux下github使用
- Linux下github使用
- Linux下使用GitHub
- Linux下使用github
- linux下配置使用github
- Linux下github使用笔记
- Linux下使用GitHub记
- Linux下github的使用
- Linux下github的使用
- linux命令行下使用github
- linux下github的使用
- 在linux下使用github
- Mac下GitHub安装及使用教程
- Mac下GitHub安装及使用教程
- VS2015下如何使用Github的教程
- github在windows下的使用教程
- simditor 限制图片格式 和 上传图片过慢
- Tensorflow MNIST for Android
- 接口请求特殊字符
- TD-LTE RRC连接重建-理论分析
- volley框架的使用
- Linux下使用github教程
- 归并排序的Java实现
- Angular4 开发环境搭建
- 推荐几款实用的Android Studio 插件
- C#将字符串转换为整型的三种方法的总结
- android gps机制分析--定位数据HAL处理
- Linux下BLAST安装及BLAST使用
- 安卓与后台进行数据交互
- MySQL 入门常用命令大全(下)