Git 操作 GitHub

Git安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
设置用户名(设置一次 以后就不用再设置了)
git config --global user.name 'TaoPanfeng'

设置邮箱(设置一次 以后就不用再设置了)
git config --global user.email '1801957499@qq.com'

查看设置
git config --list

克隆TaoPanfeng的test仓库
git clone https://github.com/TaoPanfeng/test.git

初始化(设置一次 以后就不用再设置了)
git init

查看状态
git status

工作区>>>暂存区
添加/修改文件
单个添加
git add hello.java
批量添加
git add .
删除文件 中括号是文件名 指定文件,不指定则执行所有
git rm [hello.java]

暂存区>>>本地仓库
git commit -m '提交描述' [hello.java] 中括号是文件名 指定文件,不指定则执行所有

diy01为自定义的名称
git remote add diy01 https://github.com/taopanfeng/1.git

本地仓库>>>远程仓库 这里的diy01与上面diy01对应
git push diy01 master

版本查询
多屏显示控制:空格向下翻页. b 向上翻页. q 退出.
git log
git log --oneline
git log --pretty=oneline
git reflog 常用

版本切换
git reset --hard a9d8831 常用
git push错误
1
2
3
4
5
6
7
8
9
10
11
12
The requested URL returned error:403 Forbidden while accessing

答案:私有项目,没有权限,输入用户名密码,或远程地址采用这种类型:vi .git/config


#将
【remote "origin"】
url=https://github.com/用户名/仓库名.git

修改为:
【remote "origin"】
url=https://用户名:密码@github.com/用户名/仓库名.git