centos6 git github

git的出现让传统的svn陷入尴尬的境地,分布式的版本控制是局势所需,svn目前也称要支持分布式,但至今依然是浮云。下面介绍安装git与简单实用,以github做例子。

安装

最简单,可以直接下载资源包,然后安装就好,如果是centos,可以实用yum命令安装:

?
1
# yum install git git-gui

注册github

打开github站点github.com根据提示注册就好,免费的

导入公钥

首先,要生成公钥

?
1
# ssh-keygen -t rsa -C "你注册github所用的邮箱地址"

查看公钥

?
1
# cat ~/.ssh/id_rsa.pub

复制它,然后在github右上角点击设置按钮

点击左侧菜单栏的 SSH keys 项,打开SSH keys 管理页面,然后在key管理页面中点击 Add SSH key 添加公钥 

在弹出的dialog中,Title随意填写,key栏复制你在linux机器上创建的公钥

账号配置

?
1
2
# git config --global user.name "用户名"
# git config --global user.email github注册的邮箱地址

配置好了以后,执行以下命令校验

?
1
# ssh git@github.com

如果提示:

?
1
2
3
PTY allocation request failed on channel 0
Hi lizhong8532! You've successfully authenticated, but GitHub does not provide shell access.
                                                                                             Connection to github.com closed.

表示验证通过。

创建github仓库

我们创建一个test仓库

复制test仓库ssh git地址,提交需要用

创建项目目录

?
1
2
[root@localhost ~] # mkdir test
[root@localhost ~] # cd test

初始化:

?
1
2
[root@localhost test ] # git init
Initialized empty Git repository in /root/test/ .git/

创建README.md文件

?
1
[root@localhost test ] # echo "这是一个测试的案例" > README.md

提交到本地

?
1
2
3
4
5
[root@localhost test ] # git add .
[root@localhost test ] # git commit -m "第一次提交"
[master (root-commit) c9206dc] 第一次提交
  1 files changed, 1 insertions(+), 0 deletions(-)
  create mode 100644 README.md

其中git add . 中的点表示提交这个项目下所有文件,也可以直接指定文件 git add README.md

提交到github

以上,只是提交到本地版本库,github仓库上还没有文件,现在提交到github

?
1
2
3
4
5
6
7
8
[root@localhost test ] # git remote add origin git@github.com:lizhong8532/test.git
[root@localhost test ] # git push -u origin master
Counting objects: 3, done .
Writing objects: 100% (3 /3 ), 255 bytes, done .
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:lizhong8532 /test .git
  * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

其中,git@github.com:lizhong8532/test.git是我的test仓库的提交地址,你需要改成你的test仓库地址就好。

然后刷新你的仓库,就能看见刚才提交的文件了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值