【运维知识高级篇】一篇文章带你搞懂GitHub基础操作!(注册用户+配置ssh-key+创建项目+创建存储库+拉取代码到本地+推送新代码到Github)

本篇文章简单介绍下GitHub,GitHub是一个Git版本库的托管服务,是目前全球最大的软件仓库,拥有上百万的开发者用户,适合自己使用,把代码文件放上去后可以分享出去,你的代码文件可以被任何人克隆,使开发者为开源项贡献代码变得更加容易,也可以去付费购买私有库,但是毕竟是放到别人的地方,私有库也不是绝对安全,企业中一般都放到自己的代码库,用GitLab,当然,如果你是个人开发者或者企业中用它的话,希望本篇文章能够给你带来帮助!

目录

GitHub使用

一、注册用户

二、配置ssh-key

三、创建项目

四、创建存储库

五、拉取代码到本地

六、推送新代码到GitHub


GitHub使用

一、注册用户

 搜索官网,按流程操作即可

二、配置ssh-key

由于需要将linux系统中的代码文件发送到github,所以需要先将自己linux系统与自己的github后台做免密钥以实现代码推送。

先创建ssh私钥公钥复制公钥

[root@Gitlab ~]# ssh-keygen -t rsa -C "[email protected]"    #填自己注册github的邮箱
[root@Gitlab ~]# cat .ssh/id_rsa.pub     #复制公钥

登录账号 

Linux测试下免密钥,首次需要输入yes,后续不用输入

[root@Gitlab ~]# ssh -T [email protected]
......
Are you sure you want to continue connecting (yes/no)? yes
......
Hi bosskoten! You've successfully authenticated, but GitHub does not provide shell access.
[root@Gitlab ~]# ssh -T [email protected]
Hi bosskoten! You've successfully authenticated, but GitHub does not provide shell access.

三、创建项目

右下角create可以创建 

项目里面会有title,作者,状态,供我们编写,方便我们去查阅进度完成状态,点击加号可以依次添加,编写好title后回车即可

下拉勾选 

选择状态 

依次类推可以设置多个任务

进入设置界面 

设置项目为公开 

四、创建存储库

创建一个repository存储库 

五、拉取代码到本地

拉取代码到主机 

[root@Gitlab git_test]# git pull [email protected]:bosskoten/test.git
warning: no common commits
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:bosskoten/test
 * branch            HEAD       -> FETCH_HEAD
Merge github.com:bosskoten/test

# Please enter a commit message to explain why this merge is ne
cessary,
# especially if it merges an updated upstream into a topic bran
ch.
#
# Lines starting with '#' will be ignored, and an empty message
 aborts
# the commit.
~                                                              
~                                                              
~                                                              
~                                                              
~                                                              
~                                                              
Merge made by the 'recursive' strategy.
 README.md | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 README.md

拉取成功后会找到存储库内容

[root@Gitlab git_test]# cat README.md 
# test
测试

六、推送新代码到GitHub

1、关联Github,并提交代码到Github的存储库

[root@Gitlab git_test]# git remote add origin [email protected]:bosskoten/test.git
[root@Gitlab git_test]# git push origin master
Counting objects: 12, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (11/11), 1.16 KiB | 0 bytes/s, done.
Total 11 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
remote: 
remote: Create a pull request for 'master' on GitHub by visiting:
remote:      https://github.com/bosskoten/test/pull/new/master
remote: 
To [email protected]:bosskoten/test.git
 * [new branch]      master -> master
[root@Gitlab git_test]# ls
1.txt  dev  dev_test  README.md  test

# 如果是第一次合并分支,可以将其默认设置为上游
git push -u origin <分支名称>   
# 所有分支的代码一键提交到仓库
git push --all origin           

2、查看master分支是否有push的内容 


我是koten,10年运维经验,持续分享运维干货,感谢大家的阅读和关注!

猜你喜欢

转载自blog.csdn.net/qq_37510195/article/details/130760545
今日推荐