ONOS中新建分支并关联远程库

新建分支并关联远程库

廖雪峰学习git教程网站:(多人协作)
https://www.liaoxuefeng.com/wiki/896043488029600/900375748016320
git远程仓库分支的各命令的具体解析
https://blog.csdn.net/wq6ylg08/article/details/89028412
git常用命令
https://blog.csdn.net/lexang1/article/details/45827249?utm_medium=distribute.pc_relevant. none-task-blog-2~default~BlogCommendFromMachineLearnPai2~default-1.control &depth_1-utm_source=distribute.pc_relevant.none-task-blog-2~default~BlogCommend FromMachineLearnPai2~default-1.control

公用远程库——弹性光网络私有仓库:ONOS-EON

https://github.com/login
附:https://www.zhihu.com/question/20070065/answer/1879847761 注册github(二)和安装git(六)的教程。

本地及远程库连接建立

  • 进入onos文件夹:$ cd onos
  • 本地git新建分支:$ git branch <分支名> (比如xxx-onos-eon)
  • 切换至某分支:$ git checkout <分支名> (比如xxx-onos-eon)
  • 查看当前分支状态:$ git status
  • 提交所有已添加修改: $ git add . (后接点号为增加所有修改); $ git commit -m "注释"
  • 推送本地分支到远程仓库的远程分支:$ git push <远程仓库名> <本地分支名> (:<远程分支名>) (若没有填写 <远程分支名> , <远程分支名> 默认与 <本地分支名> 相同)。git push -f 覆盖远程分支原内容,谨慎使用。

Git remote关联远程库

  • 查看当前关联库:$ git remote
    若当前已存在关联库,则删除此库:$ git remote rm <库名>
  • 建立远程库origin与本地连接 - 此处采用SSH连接,还可用https,但慢一点:$ git remote add origin git@github.com:opticalnet2/ONOS-EON.git
    查看:$ git remote -v
    结果如下:
    origin git@github.com:opticalnet2/ONOS-EON.git (fetch)
    origin git@github.com:opticalnet2/ONOS-EON.git (push)
  • 本地master分支推送至远程库origin(该名字可自定义):$ git push -u origin master
  • 若远程库名修改为xxx-dev。需要将其关联至本地:
    之前未关联的话仅需要: $ git checkout -b xxx-dev origin/xxx-dev 新建本地分支xxx-dev并关联至远程origin/xxx-dev。
    已关联过的话:$ git branch -m xxx-dev <BRANCH> 重命名该分支为xxx-dev
  • 远程先开好分支然后拉到本地:git checkout -b feature-branch origin/feature-branch//检出远程的feature-branch分支到本地
  • 本地先开好分支然后推送到远程:$ git push origin feature-branch:feature-branch//推送本地的feature-branch(冒号前面的)分支到远程origin的feature-branch(冒号后面的)分支(没有会自动创建)
  • 拉取:git fetch origin
  • 指明当前本地分支跟踪远程origin的分支:git branch -u origin/qkd-dev qkd-dev
  • 列出远程分支:$ git branch -r

完整关联过程示例

点击查看代码
yang@ubuntu18:~/onos$ git remote
origin
yang@ubuntu18:~/onos$ git remote rm origin
yang@ubuntu18:~/onos$ git remote 
yang@ubuntu18:~/onos$ git remote add eon git@github.com:opticalnet2/ONOS-EON.gityang@ubuntu18:~/onos$ git remote
eon
yang@ubuntu18:~/onos$ git remote -v
eon	git@github.com:opticalnet2/ONOS-EON.git (fetch)
eon	git@github.com:opticalnet2/ONOS-EON.git (push)
yang@ubuntu18:~/onos$ git push -u eon onos-xxx-eon
To github.com:opticalnet2/ONOS-EON.git
 ! [rejected]              onos-xxx-eon -> onos-xxx-eon (non-fast-forward)
error: failed to push some refs to 'git@github.com:opticalnet2/ONOS-EON.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.
yang@ubuntu18:~/onos$ git push -f -u eon onos-xxx-eon
Counting objects: 32975, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (15977/15977), done.
Writing objects: 100% (32975/32975), 106.65 MiB | 1.50 MiB/s, done.
Total 32975 (delta 12410), reused 32681 (delta 12247)
remote: Resolving deltas: 100% (12410/12410), done.
To github.com:opticalnet2/ONOS-EON.git
 + e38afb3754...aaeb117414 onos-xxx-eon -> onos-xxx-eon (forced update)
Branch 'onos-xxx-eon' set up to track remote branch 'onos-xxx-eon' from 'eon'.
yang@ubuntu18:~/onos$ git branch -u eon/onos-xxx-eon onos-xxx-eon
Branch 'onos-xxx-eon' set up to track remote branch 'onos-xxx-eon' from 'eon'.
###### 现在就可以在gitHub远程库里查看自己的代码啦~

posted on 2022-02-21 18:33  Limer98  阅读(116)  评论(0编辑  收藏  举报

导航