git 切换remote

    xiaoxiao2021-03-25  106

    新增 remote

    命令行操作

    git remote add gitlab git://***/***.git

    添加成功后,查看本地remotes

    git remote -v

    gitlab  http://domain.com/project.git (fetch)

    gitlab  http://domain.com/project.git (push)

    origin  https://domain.com/project.git (fetch)

    origin  https://domain.com/project.git (push)

    通过SourceTree操作

    2、push分支到指定的remote

    git push [remote-name] [branch-name],如:

    git push origin master

    通过SourceTree操作

    3、修改原有分支的remote-name

    原来已经拉取的分支,如果执行git pull / git push,仍然会从 origin上 pull / push。

    可在项目根目录 通过 vim .git/config 查看各分支的 remote-name情况。

    可通过以下命令修改remote-name:

    git branch branch_name --set-upstream-to your_new_remote/branch_name

    示例:

    git branch develop --set-upstream-to gitlab/develop

    注意:需要新的remote上存在相应的分支,才能修改,否则报错:error: the requested upstream branch 'gitlab/branch_name' does not exist。可以通过以下两种方式解决该问题:

    a. 在gitlab界面上基于master创建一个相应分支

    b. 在本地push分支过去

    4、查看分支配置

    在项目根目录执行

    vim .git/config

    转载请注明原文地址: https://ju.6miu.com/read-17313.html

    最新回复(0)