Git总结笔记3-把本地仓库推送到github

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Git总结笔记3-把本地仓库推送到github相关的知识,希望对你有一定的参考价值。

说明:此笔记在centos 7 上完成

1.配置公钥

[[email protected] ~]# ssh-keygen -t rsa -C "[email protected]"
[[email protected] ~]# cat .ssh/id_rsa.pub

注意:在本地用ssh-keygen生成密钥对后,把公钥添加到github上

2.安装git服务

[[email protected] ~]# yum -y install git

3.配置基本环境参数

[[email protected] ~]# git config --global user.name "kangvcar"
[[email protected] ~]# git config --global user.email "[email protected]"

 

4.创建本地仓库目录并初始化

[[email protected] ~]# mkdir kangvcar    
[[email protected] ~]# cd kangvcar/
[[email protected] kangvcar]# git init
[[email protected] kangvcar]# echo "ni hao kangvcar" >> test.txt

5.将项目的所有文件添加到仓库中,并commit

[[email protected] kangvcar]# git add .
[[email protected] kangvcar]# git commit -m "add test.txt"

6.到github上创建自己的Repository,名字可以不同

7.进入到新建的Repository,获取项目的地址

如地址:[email protected]:kangvcar/kangvcar.git

8.将本地仓库与远程仓库关联

[[email protected] kangvcar]# git remote add origin [email protected]:kangvcar/kangvcar.git

9.将本地仓库推送到github上

[[email protected] kangvcar]# git push -u origin master
Warning: Permanently added the RSA host key for IP address 192.30.255.112 to the list of known hosts.
Counting objects: 3, done.
Writing objects: 100% (3/3), 222 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:kangvcar/kangvcar.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

10.在github上就能看到推送的更新了

以上是关于Git总结笔记3-把本地仓库推送到github的主要内容,如果未能解决你的问题,请参考以下文章

Git学习——把文件推送到远程仓库

在自己的服务器上搭建git仓库服务器(本地推送到远程仓库远程仓库推送到本地)

git命令行将本地项目上传到仓库

git指令-添加远程仓库

如何使用git命令把代码推送到github

Git 提交将本地项目推送到github上