Git 命令
目录
建议收藏,不断更新!有一个教程很详细:Git 教程
还有一个:git常用命令--持续更新
下载软件:
学习视频:Git与Gitee简介与使用,
怎么用vscode提交 git, 【Blogs: vscode中代码提交到git】
1. git config 配置
# 添加 name
git config --global user.name "RankXiaoLong"
#添加email
git config --global user.email "email"
#修改用户名
git config --global --replace-all user.name "NewName"
#修改`邮箱`
git config --global --replace-all user.name "NewEmail"
#查看配置环境
git config --list
2. 秘钥
ssh-keygen -t rsa -C "Email"

秘钥的位置:
- Your public key has been saved in
C:\Users\Administrator/.ssh/id_rsa.pub.
open C:\Users\Administrator/.ssh
用记事本打开id_rsa.pub.
文件,复制里面的内容!
按照次序点击,title
随意取,将复制内容粘贴到Key
中


ssh -T git@github.com

3. cmd远程控制github仓库
3.1 创建仓库
指令 | 解释 |
---|---|
git init |
初始化 |
git colne |
下载仓库文件 |
# 初始化
git init
# 添加远程库信息
git remote add origin https://github.com/RankXiaoLong/ECONOMETRICS-Toturials
3.2 查看状态
指令 | 解释 |
---|---|
git remote -v |
查看远程库信息 |
git remote rm origin |
删除关联的远程库 |
git status |
查看当前git 状态 |
git branch |
查看当前git branch 状态 |
git checkout |
查看状态 |
- 查看远程库信息
git remote -v

- 删除关联的远程库
git remote rm origin
- 查看当前
git
状态
git status

- 生成新分支
git branch newbranch

- 切换新分支
git checkout newbranch

- 查看当前
git branch
状态
git branch

- 查看状态
git checkout

- 删除新分支,首先切换到主分支上,然后删除
newbranch
git checkout main
git branch -D newbranch

3.3 添加文件
指令 | 解释 |
---|---|
git add |
添加文件到仓库 |
git diff |
比较暂存区与工作区的不同 |
git commit |
提交暂存区到本地仓库 |
git rm |
删除工作区文件 |
git push origin master |
将本地的代码推送至github仓库 |
git rm -r --cached tencent
- 将本地的代码推送至github仓库
git push origin master
3.4 查看提交记录
指令 | 解释 |
---|---|
git log |
查看历史提交记录 |
git blame <file> |
以列表形式查看指定文件的历史修改记录 |
- 查看历史提交记录
git log
3.5 git fetch 命令用于从远程获取代码库
指令 | 解释 |
---|---|
git fetch |
将远程主机的最新内容拉到本地 |
git merge |
开发分支上的代码达到上线的标准后,要合并到 master 分支 |
git merge newbranch

4. 实现过程
从cmd命令将文件添加至github仓库:
首先手动创建github仓库,然后使用git clone url
,url
是仓库的地址。输入cmd命令,一般git clone
都不用git init
。因为这里已经存一个.git
文件啦!

由于刚创建仓库,只有一个README文件,

这是我想添加一个图片,下面这些指令之在git bash
中完成的。
如何快速打开文件所在位置的git bash
?点击鼠标右键,选择git bash here
- 添加文件
git add ShaSiBiEr_1.jpg
- commit 文件,辅助信息说这是一个图片。
git commit -m "photo"

- 向
github
远程仓库main
分支发生push
指令
git push -u origin main

这时刷新仓库,将会出现一张杀死比尔的剧照!

5. 常见问题
-
这个帖子包含了怎么
cmd
更新github
的仓库!: Git问题Everything up-to-date解决 -
这里新输入的密码是
token
新生成的序列码,图中的序列码是时间过期之后的样子: Invalid username or password. fatal: Authentication failed

- git上传代码出现:no changes added to commit,导致提交失败: https://blog.csdn.net/Leo062701/article/details/82194907
- git问题记录:fatal: pathspec ‘xxxx‘ did not match any files: https://blog.csdn.net/qq_37610423/article/details/109518100
- github文件夹有白色箭头并且不能打开的解决办法: https://blog.csdn.net/xiebaochun/article/details/114143346