1. 配置账户信息
# 邮箱
git config --global user.email "YourEmailAddress"
# 账户名
git config --global user.name "YourName"
2. 创建新仓库
点击New repository
输入相关信息(仓库名以myRepo
为例),然后点击Create repository
3. 初始化
在本地项目的根目录下运行,生成本地的git管理
git init
4. 添加需要上传的文件
如果要上传当前目录下的所有文件,运行
git add .
5. 提交
git commit 命令将暂存区内容添加到本地仓库中。
-m
后的内容可以是一些备注信息
git commit -m "first commit"
6. 查看提交状态
用git status
可以查看当前仓库的提交状态
git status
以上输出说明我们在最近一次提交之后,没有做任何改动,是一个 “working directory clean”,翻译过来就是干净的工作目录。
7. 添加远程版本库
点击settings
点击Developer settings
创建一个Personal access tokens
勾选repo、workflow
等之后点击Generate token
,完成创建,找个安全的地方保存生成的token
,这个页面关闭之后就再也看不到了。
添加远程版本库
git remote add origin https://[email protected]/yourName/myRepo.git
- yourToken:刚才生成的token
- yourName:账户名
- myRepo:仓库名
运行git remote -v
可以查看所有远程仓库
8. 上传项目
输入git push -u origin master
,把代码上传到github仓库
git push -u origin master
在github上看一下项目是否已经上传
成功!