git常用命令使用

一、基本操作
账号配置
git config --global user.name ‘tom’
git config --global user.email "xinfusong@163.com"

git init
git init //使用当前目录作为Git仓库,我们只需使它初始化
git init newrepo //使用我们指定目录作为Git仓库
git remote add origin https://git.lug.ustc.edu.cn/songxinfu/gittudy.git
touch test.php
git add .
git push origin master

git remote add origin https://gitee.com/xfsong/newrepo.git

https://gitee.com/xfsong/newrepo.git

git clone
git clone //从现有 Git 仓库中拷贝项目到当前目录
git clone //从现有 Git 仓库中拷贝项目到指定目录

git pull
git pull <远程主机名> <远程分支名>:<本地分支名>
//取回远程主机某个分支的更新,再与本地的指定分支合并

git add
git add 将该文件添加到缓存
git add . 将所有文件添加到缓存

git commit
将缓存区内容添加到仓库中
git commit -m “说明”

git status
查看在你上次提交之后是否有修改和分支信息

二、分支管理
git branch
git branch (branchname) 创建分支
git branch 查看分支信息
git branch -d (branchname) //删除分支

git checkout
git checkout (branchname) 切换分支

git checkout – file //会用暂存区全部或指定的文件替换工作区的文件

git checkout -b (branchname) 创建并切换分支

git merge branch1 . 合并分支

git log //git log 命令列出历史提交记录
git log --oneline 查看历史记录的简洁的版本

Git 远程仓库(Github)

git remote add [shortname] [url] //添加远程库

git remote //查看当前配置有哪些远程仓库
git remote -v

git fetch //相当于是从远程获取最新版本到本地,不会自动合并

git merge origin/master

git push [alias] [branch] //推送新分支与数据到某个远端仓库

git remote rm [别名] //删除远程仓库

git remote rm origin2

git reset HEAD //取消已缓存的内容

git reset -–hard commitid

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值