小白Git操作简洁步骤

1.下载安装Git

https://github.com/git-for-windows/git/releases/download/v2.47.0.windows.2/Git-2.47.0.2-64-bit.exe下载完后,直接安装,一直点下一步,一直到完成。

2.配置Git

配置用户名

bash 复制代码
git config --global user.name "lsp"

配置邮箱

bash 复制代码
git config --global user.email="lsp@qq.com"

查看用户配置

bash 复制代码
git config --global --list

查看系统配置

bash 复制代码
git config --system --list

查看用户和系统配置

bash 复制代码
git config -l

3.配置免密登录

生成公钥和私钥

bash 复制代码
ssh-keygen -t rsa -C "lsp@qq.com"

接着 连续敲三次回车

打开C:\Users\用户\.ssh\id_rsa.pub 文件,将里面的内容复制到对应平台(比如GitHub)

4.设置仓库别名

给代码地址增加别名

bash 复制代码
git remote add origin https://xxx.git

在不同的工作目录,如果都给对应的代码设置别名,origin对应的代码地址是不一样的

查看origin

bash 复制代码
git remote -v

5.拉取指定分支代码

bash 复制代码
git clone --single-branch -b 分支名称 origin

origin 代表 远程仓库地址https://xxx.git,在上一步设置了访问别名

6.提交代码到远程仓库

提交修改后的代码到本地仓库

bash 复制代码
把新增的、修改的都加到缓存
git add .      

把新增、和修改的、和删除的都加到缓存
git add -A

git commit -m "提交日志"

推送到远程仓库

bash 复制代码
git push -u origin 分支名称

7.更新代码

bash 复制代码
切到对应分支目录
git fetch
git merge

8.日常使用

bash 复制代码
查看仓库所有分支
git branch -a
如果看不到最新的分支,先执行git fetch origin 重新拉取

从远程仓库获取最新的分支和提交信息,但不会改变你当前的工作目录或分支
git fetch origin

查看日志
git log --oneline

查看主分支和子分支日期
git log --oneline --graph

切换分支
git checkout 分支名称

9.问题

bash 复制代码
git add 时,提示 LF will be replaced by CRLF the next time Git  touches
执行:git config --global core.autocrlf false
相关推荐
和你看星星2 天前
Git rerere:让重复冲突只解决一次
git
嘻嘻仙人5 天前
Ubuntu中 git上传自己的项目和二次上传一般流程
git·github
Patrick_Wilson5 天前
Squash Merge 的血缘陷阱:为什么删掉的代码又活了过来
前端·git·程序员
沉浸学习的匿名网友5 天前
什么是 .gitignore?为什么每个 Git 项目几乎都离不开它?
前端·git
深海鱼在掘金6 天前
Git 完全指南 —— 第3章:理解工作区、暂存区、版本库三个核心
git
江华森6 天前
Git 基础筑基:从原理到团队协作的全栈实战
git
JakeJiang7 天前
Git 必备命令指南:从日常高频到项目开发实战
git
叫我少年7 天前
Windows 中安装 git
git
深海鱼在掘金13 天前
Git 完全指南 —— 第1章:Git 概览与版本控制演进
git
noravinsc13 天前
关于Git Flow
git