这里简单介绍一下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 # 推送到远程仓库