git详解

一、git、github、gitlab的区别

Git是版本控制系统,Github是在线的基于Git的代码托管服务。 GitHub是2008年由Ruby on Rails编写而成。GitHub同时提供付费账户和免费账户。这两种账户都可以创建公开的代码仓库,只有付费账户可以创建私有的代码仓库。 Gitlab解决了这个问题, 可以在上面创建免费的私人repo。

二、Github 远程仓库

1、github.com 注册账户

2、在github上创建仓库

3、生成本地ssh key

# 下方邮箱要与github上注册的相同,并且要真实有效,使用你自己的邮箱。
[root@localhost ~]# ssh-keygen -t rsa -C 'meteor@163.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:
SHA256:RiE6UR1BtzV5avyE2uz6TNPsVHa2D2eHprghrJEkd/g meteor@163.com
The key's randomart image is:
+---[RSA 2048]----+
|    ..oo=o. o.   |
|     o ..o o...  |
|    o   . .. +   |
|     . o    = .  |
|    . + S  = o  =|
|     + *  . oo.=o|
|      o E ..o B.+|
|       o . =.* +o|
|      .   +++ . .|
+----[SHA256]-----+
[root@localhost ~]#
[root@localhost ~]# cat .ssh/id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDVThfq4brrlsPGtAknVB0TLPx+7Dd3qlxTbSIrUOsGC5Y8JuNqVTlIntZB4oNj8cSQrWvec9CKm0a8o7WwaJIiqpxurz+YpQHP2KbapftKIxsX4hPf/z+p0El1U6arQa35/xmNsq+cJLH/bDdRG+EMDhuCBmjVZOlLj/hEdeIT6s56AnnCkaWoF+sq58KCF7Tk54jRbs/YiyE4SN7FuA70r+07sA/uj0+lmuk4E190KtQUELhjX/E9stivlqiRhxnKvVUqXDywsjfM8Rtvbi4Fg9R8Wt9fpd4QwnWksYUoR5qZJFYXO4hSZrUnSMruPK14xXjDJcFDcP2eHIzKgLD1 meteor@163.com

4、复制以上的公钥,在github 中添加ssh key

5、测试

[root@localhost ~]# yum install git
........
[root@localhost ~]# ssh -T git@github.com  # 测试连通性
The authenticity of host 'github.com (13.250.177.223)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
RSA key fingerprint is MD5: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,13.250.177.223' (RSA) to the list of known hosts.
Hi meteor! You've successfully authenticated, but GitHub does not provide shell access.
[root@localhost ~]#

7、在本地添加远程仓库

[root@localhost ~]# git config --global user.name 'meteor_by'
[root@localhost ~]# git config --global user.email 'meteor@163.com'
[root@localhost ~]# git config --global color.ui true
[root@localhost ~]# git config --global color.status auto
[root@localhost ~]# git config --global color.diff auto
[root@localhost ~]# git config --global color.branch auto
[root@localhost ~]# git config --global color.interactive auto
[root@localhost ~]# git config --list | tail -3
user.name=meteor_by
user.email=meteor@163.com
color.ui=true
[root@localhost ~]#
[root@localhost ~]# ls .gitconfig 
.gitconfig
[root@localhost ~]# cat .gitconfig 
[user]
	name = meteor_by
	email = meteor@163.com
[color]
	ui = true
[root@localhost ~]#

8、连接远程仓库的方法
[(img-jdn4tVfx-1571655588619)(./assets/git_remote_method.png)]

[root@localhost python1804]# git remote -v 
origin	git@github.com:meteor/python1804.git (fetch)
origin	git@github.com:meteor/python1804.git (push)
[root@localhost python1804]#
[root@localhost python1804]#  git remote rm origin  (如果连接远程的方式不是ssh,可以删除重新添加)
[root@localhost ~]# git remote add origin git@github.com:meteor/python1804.gitgit remote add origin https://github.com/meteor/python1804.git
git push -u origin master

三、本地Git 服务器

[root@localhost ~]# useradd git
[root@localhost ~]# mkdir /git-root/
[root@localhost ~]# cd /git-root/

# 初始化本地仓库,并且没有工作区
[root@localhost git-root]# git init --bare shell.git
Initialized empty Git repository in /git-root/shell.git/
[root@localhost git-root]# chown -R git:git shell.git
[root@localhost git-root]# su - git

# 创建密钥对
[git@localhost ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/git/.ssh/id_rsa): Created directory '/home/git/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/git/.ssh/id_rsa.
Your public key has been saved in /home/git/.ssh/id
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值