前提条件:创建一个github账号,和下载git软件。
我自己使用的是windows
1.创建仓库
在你想要上传的文件夹处右击空白,进入Git Bash Here
或者用命令行(cmd)进到当前文件
开始了,输入:git init
$ git init Initialized empty Git repository in D:/code/前端练习/html5/.git/
2.选择文件
单独选择:git add 文件名
全部选择:git add .
选择文件后可以用 git status查看文件状态
$ git add task1.html --------------------------- $ git status On branch master Initial commit Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: task1.html Untracked files: (use "git add <file>..." to include in what will be committed) 1.html images/
3.提交到仓库
命令:git commit -m "输入你备注的信息"
$ git commit -m "task1" [master (root-commit) 6c8bc6b] task1 1 file changed, 53 insertions(+) create mode 100644 task1.html
4.github上创建自己的Repository和复制链接
5.将本地git和github进行关联
$ git remote add origin https://github.com/q2500819/learning.git
6.上传
上传前先:git pull origin master
若出现如上图中错误的主要原因是github中的README.md文件不在本地代码目录中
那么我们可以:git pull --rebase origin master
$ git pull --rebase origin master From https://github.com/q2500819/gitLearning * branch master -> FETCH_HEAD First, rewinding head to replay your work on top of it... Applying: task1
开始上传:git push -u origin master
$ git push -u origin master Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 550 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To https://github.com/q2500819/gitLearning.git 74d5743..5a5e12b master -> master Branch master set up to track remote branch master from origin.