小白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
相关推荐
C++ 老炮儿的技术栈6 小时前
在 Scintilla 中为 Squirrel 语言设置语法解析器的方法
linux·运维·c++·git·ubuntu·github·visual studio
余很多之很多10 小时前
命令行和neovim的git操作软件-lazygit
git
猫头虎11 小时前
GitHub下载教程:2025年最新详解从GitHub上传、下载文件、子目录与完整项目【图文教程】
git·svn·gitee·开源·github·gitea·gitcode
i建模17 小时前
将远程 main 分支同步到 develop 分支的完整指南
git
即使再小的船也能远航1 天前
【Git】实用Git操作指南:从入门到高效协作
git
<但凡.2 天前
Git 完全手册:从入门到团队协作实战(4)
git·bash
SugarPPig2 天前
Git 创建一个完全没有提交历史的 master 分支
git
lb29172 天前
git的使用,推送仓库github
git·github
躲在云朵里`3 天前
Git的使用
大数据·git·elasticsearch
悟能不能悟3 天前
在 IntelliJ IDEA 中打开这个用于设置 Git 用户名(Name)和邮箱(Email)的特定弹窗
java·git·intellij-idea