基本信息设置：
1、设置用户名
git config --global user.name 'user'

2、设置用户名邮箱
git config --global user.email 'xxxxxxxxxxxxx@qq.com'

该设置在github仓库主页显示谁提交了该文件



3、初始化仓库
git init
选择仓库My-Storage.git仓库

git remote add origin https://github.com/1051513344/My-Storage.git





4、添加文件/文件夹到暂存区
git add 文件/文件夹

5、提交修改并提交描述信息
git commit -m "描述信息"

6、查看状态
git status

7、执行添加
git push -u origin master


8、如果报错就强制上传

git push -u origin +master


在本地执行删除git文件,同步删除github上的文件

1、rm -rf 文件
2、git rm 文件
3、git commit -m "删除描述信息"
4、git push -u origin master

下载仓库中的所有文件到本地

git clone https://xxxxxxxx/x/xxx.git



利用github搭建自己的静态个人主页

1、在仓库中创建index.html
2、在设置中找到Github Pages
3、找到Source
4、在下拉列表中选择master branch

即可生效
网址为：https://github用户名.github.io/仓库名/






命令报错解决办法：
若 git push -u origin master报错
则原因是本地和github上的内容不一致导致
须执行：
git pull origin master
再执行：
git push origin master


最终解决办法：
先将远程仓库克隆到本地： git clone 仓库地址
在本地中使用： git push origin master


其他相关命令：
git log;                     查看版本日志
git log --pretty=oneline;    简略的显示版本日志
git reflog                   查看所有分支的所有操作记录
git reset --hard HEAD^;      回退到上一版本
git reset --hard HEAD^^;     回退到上上版本
git reset --hard HEAD-100;   回退到100个版本
git checkout -- file;        将file撤销到最初状态


git add 忽略文件：
1、在仓库中创建 .gitignore
2、在文件中写入 跳过的文件名
3、执行git add . 即可跳过文件



分支
git branch ;                 查看当前所在分支
git branch other;            创建other分支
git checkout other;          切换到other分支
git branch -b other;         创建other分支并且切换到other分支

将其他分支合并到master分支
1、先切换到其他分支：
git checkout other;
2、写好代码
3、切换回来：
git checkout master
4、执行将other分支合并到master
git merge other;
5、上传到master
git push origin



其他分支上传到主分支(master)
-------------------------
# other分支上的操作

1、切换到其他分支
git checkout other
2、创建分支并关联分支
git push --set-upstream origin other
执行之后就可以在github上看到other分支
3、在原先基础上修改代码文件
4、添加到other分支的工作区
git add .
5、提交申请
git commit -m "other提交"
6、上传到other分支上
git push origin

-------------------------
# 主分支上的操作

7、切换到主分支
git checkout master
8、将修改提交到主分区
git merge other
9、上传到master
git push origin

-------------------------

注：other分支的代码文件要以原master分支的代码文件为基础，若不一样的话就会造成功能不同而报错。




下次使用分支：

1、在本地克隆仓库
git clone github仓库地址
2、在本地仓库创建其他分支
git branch other
3、切换到其他分支
git checkout other
4、在本地仓库中将其他分支同步下来
git pull origin other
5、在原先基础上修改代码文件
6、添加到other分支的工作区
git add .
7、提交申请
git commit -m "other提交"
8、上传到other分支上
git push origin

-------------------------
# 主分支上的操作

9、切换到主分支
git checkout master
10、将修改提交到主分区
git merge other
11、上传到master
git push origin

-------------------------


标签

1、查看版本标签
git tag
2、创建版本标签
git tag [tag_name]
3、切换到版本
git checkout [tag_name]
4、查看标签提交的信息
git show [tag_name]
5、删除标签
git tag -d [tag_name]
6、将标签上传到github
git push origin [tag_name]



标签的具体使用

1、先添加1.0标签
git tag v1.0
(记录此时的状态)
2、编辑代码文件
test.txt
123
3、添加2.0标签
git tag v2.0
4、切换到1.0标签
git checkout v1.0
5、查看代码文件
cat test.txt
123
6、编辑代码文件
test.txt
123
456
6、切换到2.0标签
git checkout v2.0
7、查看代码文件
cat test.txt
123
456









