Git实战之将代码上传到github
【摘要】 Git实战之将代码上传到github
一、创建系统用户
1.新建lisi用户
[root@node ~]# useradd lisi
[root@node ~]# passwd lisi
Changing password for user lisi.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@node ~]# su - lisi
[lisi@node ~]$
2.创建数据存放目录
[lisi@node ~]$ mkdir -p ~/github/lisi
[lisi@node ~]$ cd github/lisi/
[lisi@node lisi]$
二、git用户信息配置
1.本地git用户的基本配置
[lisi@node lisi]$ git config --global user.name "lisi"
[lisi@node lisi]$ git config --global user.email "lisi@qq.com"
[lisi@node lisi]$ git config --global color.ui true
2.查看配置信息
[lisi@node lisi]$ cat ~/.gitconfig
[user]
name = lisi
email = lisi@qq.com
[color]
ui = true
三、本地客户端生成密钥添加到github
1.生成ssh密钥
[lisi@node lisi]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/lisi/.ssh/id_rsa):
Created directory '/home/lisi/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/lisi/.ssh/id_rsa.
Your public key has been saved in /home/lisi/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:uj5AsBRcSdJCBhiQUJEaKRjN4hvJdb0Nq+O3hqcLBQg lisi@node
The key's randomart image is:
+---[RSA 2048]----+
|E%BBo.. |
|X.Xoo. o |
|+*o=. = |
|.=. o o . |
| o. .. S |
| . oo . |
| ...+ |
| .o.= |
| +Oo. |
+----[SHA256]-----+
[lisi@node lisi]$
2.查看公钥信息
[lisi@node lisi]$ cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCUtTwJHXhh/j1InwwNS6WAw7XdwMIpcCQgDmduEpia0/OYcazQ05GKXXo+9TIvS3RF8DHmGk7lGMW0FrYyoOwSVqazZH5wmZGieFjAxLMH9AuoA+6LzGuZbhJ/xZwG9Xmr2c6w6YHU0KnmnfyGdq3Z+i3tjiOGaOMQSSt6AthEvLCuNiYojCc47i1hPiAQZB5pEIgxxECk3WoRhk3rmYAzJvCJmHeQOvpY++coyj7/8kLSPx+APgG0XMXIIqStWFlLT8LwHmx+aKIsA6n0TO32i3hoG7w3vqEsWXE+ypW+R+WTcGQyqkzrf3jYxew2L8PH148vFdmci7O2ZqijZMo1 lisi@node
3.将公钥拷贝到github
4.在github新建存储库
四、本地客户端上传操作
1.创建测试文件
[lisi@node lisi]$ echo "# test" >> README.md
[lisi@node lisi]$ touch file1 file2 aa.txt docker.yaml
[lisi@node lisi]$ ll
total 4
-rw-rw-r-- 1 lisi lisi 0 Nov 11 15:15 aa.txt
-rw-rw-r-- 1 lisi lisi 0 Nov 11 15:15 docker.yaml
-rw-rw-r-- 1 lisi lisi 0 Nov 11 15:15 file1
-rw-rw-r-- 1 lisi lisi 0 Nov 11 15:15 file2
-rw-rw-r-- 1 lisi lisi 7 Nov 11 15:14 README.md
2.创建工作区
[lisi@node lisi]$ git init
Initialized empty Git repository in /home/lisi/github/lisi/.git/
3.将测试文件添加到本地暂存区
[lisi@node lisi]$ git add .
[lisi@node lisi]$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: README.md
# new file: aa.txt
# new file: docker.yaml
# new file: file1
# new file: file2
#
4.提交文件到本地仓库
[lisi@node lisi]$ git commit -m "first commit"
[master (root-commit) 94d3ea2] first commit
5 files changed, 1 insertion(+)
create mode 100644 README.md
create mode 100644 aa.txt
create mode 100644 docker.yaml
create mode 100644 file1
create mode 100644 file2
5.添加远程仓库
[lisi@node lisi]$ git branch -M main
[lisi@node lisi]$ git remote add origin https://github.com/aa18/test.git
6.上传文件到代码仓库
git config --global http.sslVerify false
git push -u origin main
五、github查看上传结果
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
作者其他文章
评论(0)