在工作中,經常需要將同一份代碼傳到不同的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 on master ? 10:44:56
$ git remote add origin https://dev.33.cn/wangdong/alioss-file.git
- 1
- 2
~/dev33/alioss-file on master ? 10: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、完成