IT源码网

git 常用操作讲解

itxm 2021年01月14日 程序员 259 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 '[email protected]: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 '[email protected]: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

 

发布评论
IT源码网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

shell脚本监控网站状态讲解
你是第一个吃螃蟹的人
发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。