doc: update rest of the content
This commit is contained in:
1 parent
effcb133ba
commit
23c2dedabf
1 file changed
+63
-3
@@ -18,12 +18,72 @@ tags:
|
||||
检查当前的Git进程:
|
||||
```
|
||||
git remote -v
|
||||
origin https://github.com/example/example.git(获取)
|
||||
origin https://github.com/example/example.git(推送)
|
||||
origin https://gitlab.com/example/example.git(获取)
|
||||
origin https://gitlab.com/example/example.git(推送)
|
||||
```
|
||||
在我当前的场景中,为了简化操作我必须保持独特的各种GitLab账户,我将切换使用SSH而不是HTTPS。因此,您必须先将SSH密钥添加到每个GitHub和GitLab的账号上。
|
||||
|
||||
删除当前的origin远程:
|
||||
```
|
||||
git remote remove origin
|
||||
```
|
||||
```
|
||||
> 注意:如果您没有更改SSH或HTTPS,则不需要这样做。但你也可以在不移除origin的情况下轻松切换:
|
||||
```
|
||||
git remote set-url origin git@gitlab.com:example/example.git
|
||||
```
|
||||
|
||||
添加新的GitLab远程:
|
||||
```
|
||||
git remote add gitlab git@gitlab.com:example:example.git
|
||||
```
|
||||
|
||||
添加新的GitHub远程:
|
||||
```
|
||||
git remote add github git@github.com/example:example.git
|
||||
```
|
||||
|
||||
现在检查一次您当前的Git远程:
|
||||
```
|
||||
git remote -v
|
||||
gitlab https://gitlab.com/example/example.git(获取)
|
||||
gitlab https://gitlab.com/example/example.git(推送)
|
||||
github https://github.com/example/example.git(获取)
|
||||
github https://github.com/example/example.git(推送)
|
||||
```
|
||||
|
||||
现在让我们把原来的origin添加回去:
|
||||
```
|
||||
git remote add origin git@gitlab.com:example/example.git
|
||||
```
|
||||
现在我们添加GitHub作为一个额外的远程源(仅用于push):
|
||||
```
|
||||
git remote set-url --add --push origin git@gihub.com:excample/example.git
|
||||
```
|
||||
|
||||
那如果我们现在检查一下我们的Git远程:
|
||||
```
|
||||
git remote -v
|
||||
gitlab https://gitlab.com/example/example.git(获取)
|
||||
gitlab https://gitlab.com/example/example.git(推送)
|
||||
github https://github.com/example/example.git(获取)
|
||||
github https://github.com/example/example.git(推送)
|
||||
origin: https://gitlab.com/example/example.git(获取)
|
||||
origin: https://gitlab.com/example/example.git(推送)
|
||||
origin: https://github.com/example/example.git(推送)
|
||||
```
|
||||
|
||||
现在,我们必须设置我们的Git上游,因为我们在开始的时候已经移除了之前的origin远程:
|
||||
```
|
||||
git push --set-upstream origin master
|
||||
Branch 'master' set up to track remote branch 'master' from 'origin'.
|
||||
Everything up-to-date
|
||||
Branch 'master' set up to track remote branch 'master' from 'origin'.
|
||||
Everything up-to-date
|
||||
```
|
||||
|
||||
正如你从上面看到的,我们现在已经推送到GitHub和GitLab。显然没有任何改变,但从这里开始,当你做出改变、提交和推送改变时,GitHub和GitLab将同步。
|
||||
|
||||
您可能还注意到,我们单独添加了名为github和gitlab的远程,而我们只需要添加新的源远程。这只是为了让我们能够在需要时特定地获取/推送到相应的远程。
|
||||
|
||||
# 结尾:
|
||||
这主要是我个人的参考,但也可能同时对其他人有益。所以,一如既往,尽情享受吧!
|
||||
Reference in new issue
Block a user