小白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
相关推荐
如意.7595 小时前
【Linux开发工具实战】Git、GDB与CGDB从入门到精通
linux·运维·git
用户91868612868710 小时前
Git 版本控制完全指南:从入门到精通
git
简离12 小时前
Git 一次性清理已跟踪但应忽略文件
前端·git
Drone_xjw12 小时前
【环境搭建】Windows 10上使用Docker搭建本地Git仓库(Gitea)完整教程
windows·git·docker
疯狂成瘾者13 小时前
git学习目录
git·学习
曾几何时`13 小时前
Git——自用手册
git
新镜17 小时前
【git】 曾经合入的文件被删除,再次合入时,相同的文件路径并不会自动合入
git
console.log('npc')18 小时前
git commit之后,想撤销commit
git
春日见19 小时前
UniAD的逻辑,与传统自动驾驶的差异
人工智能·windows·git·机器学习·docker·容器·自动驾驶
奋斗者1号19 小时前
解决Git Push Gerrit分支失败的全流程实战
大数据·git·elasticsearch