- 安装
apt-get update -y
apt-get upgrade -y
apt install git
- 配置
git config --global user.name "username" # 引号里写用户名
git config --global user.email "email" # 引号里写email
git config --list # 查看配置
- 本地注册 ssh 配置
ssh-keygen -t rsa -C "email" # 生成密钥 全部回车即可
cat ~/.ssh/id_rsa.pub # 得到ssh-rsa 开头 email 结尾的密钥 cat 或 gedit 都可以
ssh -T git@github.com # 是否连接成功
复制密钥粘贴 settings->SSH and GPS keys->New SSH key
- 上传/连接项目到自己分支
git clone https://github.com/user/repo.git
git remote add origin <url> # 将本地仓库与GitHub上的远程仓库进行关联
git remote -v # 查看当前仓库所连接的远程仓库
git remote remove origin # remove
git branch -a # 查看所有分支
git checkout -b dev origin/dev # 创建并切换到 `dev` 分支
- 提交到特定分支 – 命令版本(第一次使用命令版 之后建议使用下方插件版)
git branch # 查看所有本地分支
git checkout <branch-name> # 切换到名为 <branch-name> 的分支
git push -u origin <branch-name> # 设置远程仓库的分支作为本地分支的跟踪分支 推送到远程仓库的分支
git add . # 将项目中的 所有文件 添加到Git的暂存区
git commit -m "test"
# 设置后使用 不需要指定远程分支
git push
- 提交到特定版本 --插件版
- view -> source control (vscode 自带)
(安装 gitlens 插件后会多出几个内容 )
在 Source Control 里 change 里将 更改添加到暂存目录 再提交到仓库
- git graph(推荐使用)
同步主分支 在其主页面右击 merge into current branch
Push 需要输密码 建议使用命令行 push - gitlens
git graph 比 gitlens 简约一些 需要会员
- view -> source control (vscode 自带)