关于git:搭建多个远程仓库将代码同时提交GithubGitee

1次阅读

共计 1349 个字符,预计需要花费 4 分钟才能阅读完成。

搭建多近程仓库

1、查看近程仓库

查看下以后我的项目的近程仓库

git remote

默认的话应该会输入:

origin

这个 origin 就是一个指向近程仓库的名称,是你在 clone 时 git 为你默认创立的。

能够通过命令查看 origin 指向的近程仓库地址:

git remote -v

输入后果:

origin  https://github.com/SoftLeaderGy/StartRedis.git (fetch)
origin  https://github.com/SoftLeaderGy/StartRedis.git (push)

该命令会显示读写近程仓库的名称和地址,我这里指向的是 Github。
2、近程仓库重命名
既然这个地址是 Github,为了好辨认,就将名称改成 github 吧。输出命令:git remote

rename <old_remote> <new_remote>

git remote rename origin github

输出查看近程仓库命令,验证下是否胜利,输入后果:

github  https://github.com/SoftLeaderGy/StartRedis.git (fetch)
github  https://github.com/SoftLeaderGy/StartRedis.git (push)

3、增加另一个近程仓库

上面咱们再增加 Gitee 上的近程仓库,首先在 Gitee 上创立一个空的仓库,名称与 Github 上雷同。
而后在【克隆 / 下载】处复制地址。


  • 输出增加近程仓库命令:git remote add <remote> <url>

git remote add gitee https://gitee.com/yang-guo-co…

再来验证下是否胜利,输入后果:

gitee   https://gitee.com/yang-guo-code/StartRedis.git (fetch)
gitee   https://gitee.com/yang-guo-code/StartRedis.git (push)
github  https://github.com/SoftLeaderGy/StartRedis.git (fetch)
github  https://github.com/SoftLeaderGy/StartRedis.git (push)

4、多个近程仓库的推送 / 拉取
有了多个近程仓库,推送和拉取再也不能像以前那样 git push 和 git pull 了,必须得加上近程仓库的名称,以辨认操作的是哪个近程仓库。命令如下:git push <remote> <branch>、git pull <remote> <branch>:

git push github main
git pull github main

git push gitee main
git pull gitee main

如果不想每次操作都带着分支,须要将本地分支与近程分支进行关联:git branch –set-upstream-to=<remote>/<remote_branch> <local_branch>

git branch --set-upstream-to=gitee/main main

关联后就能够不指定分支了

git push github
git pull github

git push gitee
git pull gitee
正文完
 0