git 常用操作

虾米哥 阅读:848 2021-01-14 09:33:11 评论:0

在gitee上新创建项目后,将本地的项目提交到git上去

 

git init

touch README.md

git add .

git commit -m 'first commit'

git remote add origin https://gitee.com/abc/abc.git

git push -u origin master

 

将项目push到仓库的时候,因为仓库中的项目非空,所以会报错:

To gitee.com:abc/abc.git 
 ! [rejected]        master -> master (fetch first) 
error: failed to push some refs to 'git@gitee.com:abc/abc.git' 
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.

 所以先pull项目

git pull

git push -u origin master

 

报错:

To gitee.com:abc/abc.git 
 ! [rejected]        master -> master (non-fast-forward) 
error: failed to push some refs to 'git@gitee.com:abc/abc.git' 
hint: Updates were rejected because the tip of your current branch is behind 
hint: its remote counterpart. Integrate the remote changes (e.g. 
hint: 'git pull ...') before pushing again. 
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

 提示版本落后于线上的项目,线上的内容是没有用的,所以强制推送一次

git push -u -f origin master

 

成功后创建多个分支:

 查看本地分支和远程分支

git branch 
 
git branch -r

 

创建分支

git checkout -b v1.0 origin/master

git push origin HEAD -u

 

标签:开发工具
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号