git解除与远程分支的关联

在工作中,经常需要将同一份代码传到不同的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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

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

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

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

git remote remove origin
  • 1

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

~/dev33/alioss-file onmaster10:44:56
$ git remote add origin https://dev.33.cn/wangdong/alioss-file.git
  • 1
  • 2
~/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.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

6、完成

猜你喜欢

转载自blog.csdn.net/qq_15037231/article/details/80924041