Git 取消远程分支关联,并关联到新的远程分支,将代码推上去

简介: 在工作中,经常需要将同一份代码传到不同的git仓库中去如果本地同样一份代码,已经关联了一个与远程分支,那么怎么才能解除原程分支,并关联到一个新的分支将代码提交到新的分支上去呢? 1、如果你已经在远程创建了一个分支,远程分支地址:https://xxxxxxx/wangdong/helloworld.

在工作中,经常需要将同一份代码传到不同的git仓库中去

如果本地同样一份代码,已经关联了一个与远程分支,那么怎么才能解除原程分支,并关联到一个新的分支将代码提交到新的分支上去呢?
1、如果你已经在远程创建了一个分支,远程分支地址:https://xxxxxxx/wangdong/helloworld.git
2、从命令行创建一个新的仓库,关联到该远程分支

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://xxxxxxx/wangdong/helloworld.git
git push -u origin master

3、如果本地的代码,没有关联任何远程分支

git remote add origin https://xxxxxxx/wangdong/helloworld.git
git push -u origin master

4、如果本地代码,已经关联了远程分支,则需要先解除关联

git remote remove origin

5、解除后、重新关联新的远程分支,并将代码传上去

~/dev33/alioss-file onmaster10:44:56
$ git remote add origin https://dev.33.cn/wangdong/alioss-file.git
~/dev33/alioss-file onmaster10:45:01
$ git push -u origin master
Counting objects: 102, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (82/82), done.
Writing objects: 100% (102/102), 62.52 KiB | 7.81 MiB/s, done.
Total 102 (delta 26), reused 0 (delta 0)
To https://dev.33.cn/wangdong/alioss-file.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

6、完成

目录
相关文章
|
1月前
|
开发工具 git 开发者
|
1月前
|
开发工具 git
|
1月前
|
开发工具 git C++
【git 实用指南】git下载、拉取 代码
【git 实用指南】git下载、拉取 代码
158 2
|
1月前
|
开发工具 git
【git 实用指南】git 上传代码
【git 实用指南】git 上传代码
33 2
|
1月前
|
开发工具 git 开发者
|
1月前
|
开发工具 git
|
4天前
|
开发工具 git
git 拉取代码仓库代码报错(合并错误 refusing to merge unrelated histories)
git 拉取代码仓库代码报错(合并错误 refusing to merge unrelated histories)
13 0
|
8天前
|
数据可视化 开发工具 git
Git代码版本管理入门
Git代码版本管理入门
17 0
|
26天前
|
开发工具 C语言 数据安全/隐私保护
git提交代码到远端仓库的方法详解
git提交代码到远端仓库的方法详解
|
28天前
|
算法 开发工具 git
【git 实用指南】git 增加 本地代码 git add 相关命令和复杂情况需求
【git 实用指南】git 增加 本地代码 git add 相关命令和复杂情况需求
92 0

相关实验场景

更多