git提交工程到分支上
将本地仓库的内容提交到远程仓库分支上,本示例在window下测试使用,Linux系统大同小异。
1. 初始化本地仓库
git init
2. 将本地内容添加到git
git add . //将当前目录下的所有文件添加进提交内容
3. 创建提交说明
git commit -m "第一次提交"
4. 关联远程仓库
git remote add origin https://github.com/用户名/仓库名
5. 获取远程仓库分支情况
git fetch
git branch -a
6.创建本地新分支
git branch XRROS-APP
7. 推送本地分支到远程分支上
git checkout XRROS-APP //切换本地分支到XRROS-APP上,默认是master
git push origin XRROS-APP:XRROS-APP
注意:前一个XRROS-APP
是本地分支,后一个是远程分支
如果在push的时候,出现以下错误:
To https://github.com/yuanchao614/wecoder.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/yuanchao614/wecoder.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.
出现以上的non-fast-forward
错误,请执行以下指令
git pull origin 分支名称 --allow-unrelated-histories
可能会出现vim编辑不用管直接保存退出就行
然后建议做完上一步之后再重新:
git add .
git commit -m '提交说明'
git push origin XRROS-APP:XRROS-APP
如果出现以下内容,则表明推送成功了
$ git push origin XRROS-APP:XRROS-APP
Enumerating objects: 586, done.
Counting objects: 100% (586/586), done.
Delta compression using up to 4 threads
Compressing objects: 100% (553/553), done.
Writing objects: 100% (584/584), 12.38 MiB | 395.00 KiB/s, done.
Total 584 (delta 76), reused 0 (delta 0)
remote: Resolving deltas: 100% (76/76), done.
To https://github.com/xxx/XiaoR-ROS
a904c7f..169a2bd XRROS-APP -> XRROS-APP