admin 发表于 2019.10.15 03:49

使用Git在Github上传项目的新手入门教程

新手如何使用Git 给 Github 上次项目代码

新手教程

下载 Git https://git-scm.com/downloads

打开Github,注册账号

Repositories点后面的 New,新建项目,写名字,写描述,选 Public 公共权限。

点击创建后,记住git的网址,忘了的可以点项目页面的 Clone or download ,就可以看到了

例如https://github.com/loadream/chenyifaer.git

准备工作

比如项目文件是在D盘的 chenyifaer 文件夹,Github的git是 https://github.com/loadream/chenyifaer.git

把要上传的文件放到 D盘的 chenyifaer 文件夹内。

运行git-bash.exe

在git-bash.exe界面输入以下内容,替换成自己的账号和邮箱

git config --global user.name loadream
git config --global user.email admin<span id="kM0.7548849653118352">@loadream.com</span>



首先使用cd命令打开 D盘的chenyifaer

d:cd chenyifaer

在当前项目的目录中生成本地的git管理,输入下面内容

git init
出现 git 不是内部或外部命令,也不是可运行的程序说明没有环境变量,直接去官网下载exe的安装包安装,别用便携版又或者自己配置一下环境变量,学java python的基本都会
会发现文件夹内多了一个.git的文件夹。

把github的库克隆下来到本地
git clone https://github.com/loadream/chenyifaer.git
将项目上所有的文件添加到仓库,果想添加某个特定的文件,只需把 . 换成这个特定的文件名即可(加上空格)
git add .

输入提交注释,比如这样

git commit -m "first commit"

将本地的仓库关联到 github 的仓库

git remote add origin https://github.com/loadream/chenyifaer.git
在 git-bash.exe 端输入

ssh-keygen -t rsa -C "这里是你的注册邮箱"
敲三次回车,会生成一个id_rsa.pub的密匙,右键记事本打开。

登录github.点你的项目,再点setting - Deploy keys - add Deploy keys

填写你的密匙,确定。

在 git-bash.exe 运行

ssh –t git@github.com

如果出现ssh: Could not resolve hostname \342\200\223t: Name or service not known的错误
执行
ssh -t -p 22 git@github.com
输入yes。

再试试 ssh –t git@github.com



将本地代码推到Github上

git push -u origin master

会弹出一个对话框,基本就是选Master,以及输入你的Github的账号和密码。最后等待完成即可。


上传成功后会出现这么一行

Branch 'master' set up to track remote branch 'master' from 'origin'.

未来就是本地修改代码,然后再push推送。








页: [1]
查看完整版本: 使用Git在Github上传项目的新手入门教程