git 常用操作

在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

 

posted @ 2019-08-28 09:41  kangjie  阅读(199)  评论(0编辑  收藏  举报