上传本地项目代码到Gitee或Github

1、登录Gitee创建一个与项目名字相同的仓库,如book
上传本地项目代码到Gitee或Github_第1张图片
2、打开Git命令窗口Git Bash
上传本地项目代码到Gitee或Github_第2张图片
3、切换到项目的目录,如E:\workspace\mybatis-spring\book
上传本地项目代码到Gitee或Github_第3张图片
4、执行以下命令

# 1、初始化
$ git init
Initialized empty Git repository in E:/workspace/mybatis-spring/book/.git/
# 2、添加远程仓库
$ git remote add origin https://gitee.com/moss_huang/book.git

# 3、同步远程仓库到本地仓库
$ git pull origin master
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From https://gitee.com/moss_huang/book
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master

# 4、添加要上传的文件到缓存区
$ git add . 或者 git add + 文件名
warning: LF will be replaced by CRLF in book.sql.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in logs/book.log.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in src/main/webapp/WEB-INF/js/bootstrap.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in src/main/webapp/WEB-INF/js/jquery-3.3.1.min.js.
The file will have its original line endings in your working directory

# 5、上传代码到本地仓库
$ git commit -m '测试上传代码'

# 6、将本地仓库推送到远程仓库
$ git push origin master
Enumerating objects: 66, done.
Counting objects: 100% (66/66), done.
Delta compression using up to 4 threads
Compressing objects: 100% (49/49), done.
Writing objects: 100% (65/65), 81.20 KiB | 2.54 MiB/s, done.
Total 65 (delta 1), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-3.8]
To https://gitee.com/moss_huang/book.git
   dd98d95..389971a  master -> master

5、刷新Gitee就可以看到提交的项目了
上传本地项目代码到Gitee或Github_第4张图片

你可能感兴趣的:(git)