boxmoe_header_banner_img

Hello! 欢迎来到 XG 博客!

加载中

文章导读

git学习:常用命令


avatar
XenonXG 2025年11月16日 1.67k

全局配置

设置用户信息(全局配置,只配置这一次,必须配置):

git config --global user.name "名字"
git config --global user.email "邮箱"
#查看配置信息
git config --list

本地仓库命令

#初始化本地参数
git init
#查看文件状态,可以查看到文件冲突
git status
#直接查看文件冲突的差异
git diff
#将文件加入暂存区
git add <文件名字或者直接 * . 表示所有文件/文件夹>
#将暂存区的文件传入本地仓库
git commit -m "这里是提示文字" <文件名字或者直接 * . 表示所有文件/文件夹>
#显示上传日志
git log
#更加好看的显示日志
git reflog
#将暂存区文件取消暂存或切换到指定版本
git reset <文件>
git reset --hard <版本号>

远程仓库命令

#从远程仓库克隆
git clone <url>
#添加,关联仓库、
git remote add <shortname> <url>
#移除关联的仓库
git remote remove <shortname>
#给远端仓库推送
git push <shortname> <branch>
#查看关联的仓库信息
git remote [-v]
#从远程仓库拉取
git pull <shortname> <branch>

分支相关命令

查询分支  git branch 
#列出所有本地分支
git branch         
#列出所有远程分支
git branch -r
#列出所有本地分支和远程分支
git branch -a         

创建分支

git branch <分支名称>

切换分支

git checkout <分支名称>

推送到远程分支

git push <远程仓库名字> <分支名字>

合并分支

git merge <分支名字>


评论(4)

查看评论列表
评论头像
足球生活 2026年03月07日
挺不错的样子嘛!
评论头像
333985 2026年05月13日
wish you all the best
评论头像
ExoWatts 2026年07月18日
Great content! Keep up the good work!
评论头像
555329 2026年09月05日
So,I like it

发表评论

表情 颜文字
插入代码