小白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
相关推荐
qq_5470261791 小时前
Git 使用指南
git
XiaoHu02072 小时前
Linux多线程(详细全解)
linux·运维·服务器·开发语言·c++·git
*才华有限公司*3 小时前
RTSP视频流播放系统
java·git·websocket·网络协议·信息与通信
juelianhuayao4 小时前
Git错误提交后如何快速删除本次commit
git
chen<>4 小时前
Git原理与应用
大数据·git·elasticsearch·svn
小兔崽子去哪了5 小时前
Git 专题
git
金米kk5 小时前
git pull时报错Your local changes to the following files would…的解决办法
git
超级罗伯特5 小时前
git一次性完成仓库下载及所有分支获取
git·git仓库拉取
BUTCHER56 小时前
Git 基础命令
git
M malloc6 小时前
当你有两个git账号时,此时你gitpush冲突后如何解决push问题
git