Git常见操作

一、全局配置命令

配置级别:

–local(默认,高级优先):只影响本地仓库
–global(中优先级):只影响所有当前用户的git仓库
–system(低优先级):影响到全系统的git仓库

1.1 设置用户名和邮箱

git config --global user.name "FELaoL"  //设置用户名
git config --global user.email felaol@sina.com  //设置邮箱

1.2 查看用户名和邮箱

git config user.name
git config user.email

1.3 查看配置信息

git config --list

1.4 强制清除git配置信息

git config --global --unset credential.helper

1.5 记住git配置信息

git config --global credential.helper store

二、常用命令

2.1 初始化仓库

git init 

2.2 对状态的跟踪

git status

2.3 添加文件内容到暂存区(同时文件被跟踪)

git add

2.4 添加所有文件

git add .

2.5 提交代码到本地分支

git commit -m "备注信息"

2.6 查看提交历史记录

git log

三、分支操作

3.1 显示所有分支信息

git branch -v  //或者 git branch -a

3.2 创建一个分支,但依然停留在当前分支

git branch <branchName>

3.3 删除一个分支

git branch -d <branchName>

3.4 切换分支

git checkout <branchName>

3.5 创建一个分支并切换到该分支

git checkout -b <branchName> 

3.9 合并分支

git merge <branchName>  //在目标分支下执行这段;可将test中的代码合并到目标分支中

在这里插入图片描述

四、远程操作

4.1 初始化本地仓库

git init <directory>  //<directory>是可选的,如果不指定,将使用当前目录。

4.2 推送到远程

git push <remote name>  //将本地历史推送到远程
git push <remote name> <branch>  //将更改推送到特定分支

4.3 添加远程仓库

git remote add <remote name> <url>

//例如:git remote add origin git://127.0.0.1/abc.git

4.4 移除远端仓库

git remote remove origin

4.5 查看远程仓库信息

git remote -v 

4.6 获取更改

git fetch <remote name>  //从远程存储库中获取更改
git fetch <remote name> <branch>  //从特定分支获取更改

4.7 git pull = git fetch + git merge

git pull <remote name> <branch>

4.8 克隆一个远程仓库作为本地仓库

git clone <url>  
git clone -b <指定分支名>  <远程仓库地址> //克隆指定分支

4.9 服务器新建了新的分支,本地刷新分支

git remote update origin -p
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值