#Git常用命令
##查看配置:
git --version //查看git的版本信息
git config --global user.name //获取当前登录的用户
git config --global user.email //获取当前登录用户的邮箱
##登录git:
/* 如果刚没有获取到用户配置,则只能拉取代码,不能修改 要是使用git,你要告诉git是谁在使用*/
git config --global user.name ‘userName’//设置git账户,userName为你的git账号
git config --global user.email \'email’设置git账户,email为你的git邮箱
##创建一个文件夹
mkdir nodejs //创建文件夹nodejs
cd nodejs //切换到nodejs目录下
##初始化git仓库
git init //在nodejs文件夹下初始化一个仓库,此时文件里会到一个.git的隐藏文件夹
git clone XXX//克隆一份代码到本地仓库
git pull //把远程库的代码更新到工作台
git pull --re origin master //强制把远程库的代码跟新到当前分支上面
git fetch //把远程库的代码更新到本地库
git add . //把本地的修改加到stage中
git commit -m ‘comments here’ //把stage中的修改提交到本地库
git push //把本地库的修改提交到远程库中
git branch -r/-a //查看远程分支/全部分支
git checkout master/branch //切换到某个分支
git checkout -b test //新建test分支
git checkout -d test //删除test分支
git merge master //假设当前在test分支上面,把master分支上的修改同步到test分支上
git merge tool //调用merge工具
git stash //把未完成的修改缓存到栈容器中
git stash list //查看所有的缓存
git stash pop //恢复本地分支到缓存状态
git blame someFile //查看某个文件的每一行的修改记录()谁在什么时候修改的)
git status //查看当前分支有哪些修改
git log //查看当前分支上面的日志信息
git diff //查看当前没有add的内容
git diff --cache //查看已经add但是没有commit的内容
git diff HEAD //上面两个内容的合并
git reset --hard HEAD //撤销本地修改
##分支相关
1、推送本地分支local_branch到远程分支 remote_branch并建立关联关系
a.远程已有remote_branch分支并且已经关联本地分支local_branch且本地已经切换到local_branch
git push
b.远程已有remote_branch分支但未关联本地分支local_branch且本地已经切换到local_branch
git push -u origin/remote_branch
c.远程没有有remote_branch分支并,本地已经切换到local_branch
git push origin local_branch:remote_branch
2、删除本地分支local_branch
git branch -d local_branch
3、删除远程分支remote_branch
git push origin :remote_branch
git branch -m | -M oldbranch newbranch 重命名分支,如果newbranch名字分支已经存在,则需要使用-M强制重命名,否则,使用-m进行重命名。
git branch -d | -D branchname 删除branchname分支
git branch -d -r branchname 删除远程branchname分支
4、查看本地分支
git branch
5、查看远程和本地分支
git branch -a
6.列出本地分支:
git branch
7.删除本地分支:
git branch -D BranchName
其中-D也可以是–delete,如:
git branch --delete BranchName
8.删除本地的远程分支:
git branch -r -D origin/BranchName
9.远程删除git服务器上的分支:
git push origin -d BranchName
其中-d也可以是–delete,如:
git push origin --delete BranchName
团队协作git操作流程:
• 克隆一个全新的项目,完成新功能并且提交:
- git clone XXX //克隆代码库
- git checkout -b test //新建分支
- modify some files //完成修改
- git add . //把修改加入stage中
- git commit -m ‘’ //提交修改到test分支
- review代码
- git checkout master //切换到master分支
- git pull //更新代码
- git checkout test //切换到test分支
- git meger master //把master分支的代码merge到test分支
- git push origin 分支名//把test分支的代码push到远程库
• 目前正在test分支上面开发某个功能,但是没有完成。突然一个紧急的bug需要处理 - git add .
- git stash
- git checkout bugFixBranch
- git pull --re origin master
- fix the bug
- git add .
- git commit -m ‘’
- git push
- git checkout test
- git stash pop
- continue new feature’s development**
继续阅读与本文标签相同的文章
Vue.js新手入门指南
360家庭安全大脑发布 16路视频分析厉害了
-
有关厂商都在积极布局功率碳化硅
2026-05-18栏目: 教程
-
反向链接对网站权重有影响吗?
2026-05-18栏目: 教程
-
国内首创:海南台风灾害影响评估三维模拟系统投入试运行
2026-05-18栏目: 教程
-
大智能时代,需要什么样的产品经理
2026-05-18栏目: 教程
-
怎样才能让用户更喜欢你的APP应用
2026-05-18栏目: 教程
