Git命令汇总

16 篇文章 5 订阅
3 篇文章 0 订阅

Git命令汇总

  • Git的config配置相关命令
#查看git 版本
git --version

# 查看当前仓库git配置
git config --list

#查看git全局配置
git config --global --list

#修改git当前仓库配置(例:修改账号和邮箱)(①直接不使用--global ②使用local)
git config   user.name 'XXX' 
git config   user.email 'XXX' 
git config  --local  user.name 'XXX' 
git config  --local user.email 'XXX' 

#修改git全局配置(例:修改账号和邮箱)
git config --global user.name "username"
git config --global user.email "email"

#设置git记住密码(默认15分钟)
 git config --global credential.helper cache 
#设置git记住密码一个小时(1小时)
git config credential.helper 'cache --timeout=3600' 
#设置git长期记住密码
git config --global credential.helper store 


#Git清除本地缓存
git rm -r --cached .
  • 清空凭证助手
git config --system --unset credential.helper
# 除了system外,还有global、local等范围
# 使用 git config --list 命令这是展示配置属性,只要不存在credential.helper表示清除成功
  • 配置凭证助手
git config --global credential.helper store
# 清除成功后,每次远程操作pull/push/fetch时需要手动输入密码啊。
# 执行这个命令,开启凭证助手,一次输入密码认证成功后会被存储下来。
  • Git克隆项目代码
#不指定分支克隆代码(默认master分支)
git clone 克隆地址

#指定分支克隆代码
git clone -b 分支  克隆地址

#克隆项目自定义本地仓库名称
git clone 克隆地址 仓库名称
  • 在本地新建分支,关联远程分支,并切换到本地的分支,进行开发
#创建分支
git branch 分支名称

#切换分支
git checkout 分支名称

#创建本地分支
git checkout -b 分支名称

#创建分支并切换
git checkout -b test origin/分支名称
  • 修改本地项目的仓库地址
#当本地项目在gitlab远程仓库的路径发生变化时
git remote remove origin
git remote add origin 新仓库地址

#查看配置是否已修改(remote.origin.url=)\
git config -l
  • 删除分支
#删除远程仓库分支
git push origin --delete 分支名

#删除本地分支
git branch -d 分支名
  • 合并分支
git marge --no--ff 分支名
  • 拉取远程仓库分支代码
git pull origin 分支名称
  • Git提交代码到本地库
#添加目录
git add.   (注意有个点)

#提交到本地库
git commit -m "备注"
  • Git查看分支(绿色为本地仓库分支,红色为远程仓库分支)
#查看所有分支
git branch -a

#查看当前分支
git branch
  • Git提交代码到远程仓库
#默认提交到master分支
git push

#提交到指定分支
git push origin 分支名称
  • 将远程仓库所有代码拉取到本地库
git fetch
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hippoDocker

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值