小白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
相关推荐
Mr_Dwj5 小时前
【工具】Git 子仓库管理
git
Rysxt_13 小时前
Git Rebase 变基教程:作用、使用场景与合并的区别
git·变基
刘某某.14 小时前
提交 git 的三种方式
git
bigHead-16 小时前
Git 修改远程仓库地址的几种方法
git
杀手不太冷!17 小时前
Jenkins的安装与使用;git clone url的时候,url为http和ssh时候的区别
git·http·jenkins
qq_2290580118 小时前
GIT使用方法
git
YMGogre18 小时前
Git 多人协作开发
git
凯子坚持 c1 天前
Git 多人协作深度解析:从工作流模拟到仓库维护
git
要站在顶端1 天前
克隆大型仓库卡住(7%每次就卡住了)
git
五月底_1 天前
上传大量文件到github repo
git·github