git在工作中的使用

1 篇文章 0 订阅

这里简单介绍一下git的常用命令


1、克隆代码

我们知道,第一次本地没有项目,所以需要先下载项目到本地。要下载别人的远程代码到本地,可以使用

git clone https://...   # https://...为远程仓库地址

基本使用一次之后,就不用每天克隆远程代码到本地了

2、更新本地代码


更新方法一

后面不需要每天克隆代码,只需要获取最新的远程代码即可

git pull
更新方法二

在本地新建一个new-master分支,并将远程origin仓库的master分支代码下载到本地new-master分支

git fetch origin master:new-master

合并new-master分支

git merge new-master

最后可以删除分支

git branch -d new-master # -D 可以强制删除分支

3、推送代码到远程仓库

第一天克隆代码本地后,修后需要上传到远程仓库,依次使用命令
1、上传到本地仓库

git add .

2、提交备注

 git commit -m "name"  # name为备注信息

3、推送到远程仓库

git push https://...   # https://...为远程仓库地址

可能第一次推送会有些问题

error:failed to push some refs to 'https://..."
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push --help’ for details.

解决方法:

git pull origin master # master为远程分支名
git push origin master # 推送到远程仓库
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值