git常用命令总结

先在本地已有的程序文件夹创建本地仓库,将本地仓库push到远程仓库时经常报错推送失败,后来选择先创建远程仓库,将远程仓库克隆到本地,再将已有的程序文件夹复制到克隆的本地仓库中,再push,就没有报错。

下面总结一下我在项目中常用的git命令:

  • 克隆远程仓库:git clone [url]
例如:$ git clone https://github.com/libgit2/libgit2
  • 克隆远程仓库指定分支:git clone -b <指定分支名> <远程仓库地址>
例如:$ git clone ljy https://github.com/libgit2/libgit2
  • 在克隆远程仓库的时候,自定义本地仓库的名字:git clone [url] [name]
例如:$ git clone https://github.com/libgit2/libgit2 mylibgit
  • 检查当前文件状态:$ git status
  • 将项目的所有文件添加到缓存中:$ git add .  
  • 提交更新:$ git commit
  • 提交更新并带注释:$ git commit -m “信息”
例如:$ git commit -m "Story 182: Fix benchmarks for speed"
  • 推送到远程仓库:git push [remote-name] [branch-name]
例如:$ git push origin master
  • 提交到远程仓库的某个分支上:git push origin [本地分支名]:[远程分支名]
例如:将hello_git_branch分支提交到远程仓库的master上面:git push origin hello_git_branch:master
  • 新建分支:$ git checkout -b [分支名]
例如:$ git checkout -b iss53
它是下面两条命令的简写:
$ git branch iss53
$ git checkout iss53
  • 切换回 master 分支:$ git checkout master
  • 分支的合并:$ git merge [分支名]
例如:$ git merge iss53
  • 查看远程分支(包括本地和远程):$ git branch
  • 修改本地分支名:$ git branch -m old_name new_name
  • 删除本地分支:$ git branch -d <BranchName>
  • 删除远程分支:$ git push origin --delete <BranchName>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值