• git 设置 upstream


    --set-upstream  的作用, 基本上是 改变一个分支的 merge 头。 其他的不变。 


    D:\code\git\mw\me\umc-portal>git pull main2 dev
    From http://192.169.2.234/umc/umc-portal
    * branch dev -> FETCH_HEAD
    Auto-merging utils/src/main/java/com/lk/umc/portal/util/file/UploadFileUtil.java
    CONFLICT (content): Merge conflict in utils/src/main/java/com/lk/umc/portal/util/file/UploadFileUtil.java
    Automatic merge failed; fix conflicts and then commit the result.

    D:\code\git\mw\me\umc-portal>git pull main2 dev
    error: You have not concluded your merge (MERGE_HEAD exists).
    hint: Please, commit your changes before merging.
    fatal: Exiting because of unfinished merge.

    D:\code\git\mw\me\umc-portal>git pull main2 dev
    From http://192.169.2.234/umc/umc-portal
    * branch dev -> FETCH_HEAD
    Already up to date.

    D:\code\git\mw\me\umc-portal>git pull
    Already up to date.

    D:\code\git\mw\me\umc-portal>git pull main2
    remote: Enumerating objects: 877, done.
    remote: Counting objects: 100% (877/877), done.
    remote: Compressing objects: 100% (288/288), done.
    remote: Total 877 (delta 264), reused 767 (delta 232)
    Receiving objects: 100% (877/877), 314.45 KiB | 2.07 MiB/s, done.
    Resolving deltas: 100% (264/264), completed with 72 local objects.
    From http://192.169.2.234/umc/umc-portal
    0b0ec1e7..4ba2af93 dev -> main2/dev
    97643ee7..db0057cd dev-aim2.0 -> main2/dev-aim2.0
    * [new branch] revert-c42d09a5 -> main2/revert-c42d09a5
    c42d09a5..16bb46d5 umc_portal_gw -> main2/umc_portal_gw
    68c7df09..c1b7af18 管理服务-代码扫描漏洞修复 -> main2/管理服务-代码扫描漏洞修复
    You asked to pull from the remote 'main2', but did not specify
    a branch. Because this is not the default configured remote
    for your current branch, you must specify a branch on the command line.

    D:\code\git\mw\me\umc-portal>git remote -vv
    main2 http://192.169.2.234/umc/umc-portal.git (fetch)
    main2 http://192.169.2.234/umc/umc-portal.git (push)
    origin http://192.169.2.234/lk/umc-portal.git (fetch)
    origin http://192.169.2.234/lk/umc-portal.git (push)

    remote 和 upstream 的区别

    D:\code\git\mw\me\umc-portal>git pull main2
    remote: Enumerating objects: 15, done.
    remote: Counting objects: 100% (15/15), done.
    remote: Compressing objects: 100% (9/9), done.
    remote: Total 15 (delta 0), reused 0 (delta 0)
    Unpacking objects: 100% (15/15), 17.30 KiB | 33.00 KiB/s, done.
    From http://192.169.2.234/umc/umc-portal
    d742db5c..cb57963c dev-aim2.0 -> main2/dev-aim2.0
    You asked to pull from the remote 'main2', but did not specify
    a branch. Because this is not the default configured remote
    for your current branch, you must specify a branch on the command line.


    D:\code\git\mw\me\umc-portal>git pull
    There is no tracking information for the current branch.
    Please specify which branch you want to merge with.
    See git-pull(1) for details.

    git pull <remote> <branch>

    If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=<remote>/<branch> devlk

    ++++++++++


    一。使用场景: 本地新建一个分支后,必须要做远程分支关联。如果没有关联,git会在下面的操作中提示你显示的添加关联。关联目的是如果在本地分支下操作: git pull, git push ,不需要指定在命令行指定远程的分支.

    下面的方式 是行不通的!!

    D:\code\git\mw\me\umc-portal>git pull main2 devlk
    fatal: couldn't find remote ref devlk

    D:\code\git\mw\me\umc-portal>git pull main2:dev devlk
    ssh: Could not resolve hostname main2: Name or service not known
    fatal: Could not read from remote repository.

    Please make sure you have the correct access rights
    and the repository exists.


    看来只有 通过 --set-upstream-to=

    upstream 其实是一个仓库名字,但是它是一个概念, 而 origin 这样的是 具体名字。当然, 我们也可以使用它作为名字,因为他不是关键字, 语法是:
    git pull upstream master

    D:\code\git\mw\me\umc-portal>git remote add upstream https://github.com/devopscube/vagrant-examples.git
    error: remote upstream already exists.

    D:\code\git\mw\me\umc-portal>git remote -vv
    ...
    upstream https://github.com/devopscube/vagrant-examples.git (fetch)
    upstream https://github.com/devopscube/vagrant-examples.git (push)

    +++ 创建一个新的 远程分支

    D:\code\git\mw\me\umc-portal>git push -u origin
    fatal: The current branch devlk has no upstream branch.
    To push the current branch and set the remote as upstream, use

    git push --set-upstream origin devlk


    D:\code\git\mw\me\umc-portal>git push -u origin devlk
    Enumerating objects: 348, done.
    Counting objects: 100% (281/281), done.
    Delta compression using up to 16 threads
    Compressing objects: 100% (62/62), done.
    Writing objects: 100% (175/175), 68.62 KiB | 9.80 MiB/s, done.
    Total 175 (delta 72), reused 138 (delta 45), pack-reused 0
    remote: Resolving deltas: 100% (72/72), completed with 24 local objects.
    remote:
    remote: To create a merge request for devlk, visit:
    remote: http://192.169.2.234/luokai/umc-portal/merge_requests/new?merge_request%5Bsource_branch%5D=devlk
    remote:
    To http://192.169.2.234/luokai/umc-portal.git
    * [new branch] devlk -> devlk
    Branch 'devlk' set up to track remote branch 'devlk' from 'origin'.

    ----

    D:\code\git\mw\me\umc-portal>git pull --set-upstream origin dev3:dev2
    From http://192.169.2.234/luokai/umc-portal
    ! [rejected] dev3 -> dev2 (non-fast-forward)

    D:\code\git\mw\me\umc-portal>git pull --set-upstream origin dev4:dev2
    fatal: couldn't find remote ref dev4

    D:\code\git\mw\me\umc-portal>git pull --set-upstream origin HEAD:dev2
    From http://192.169.2.234/luokai/umc-portal
    ! [rejected] -> dev2 (non-fast-forward)

    为什么被拒绝? 大概是因为 HEAD:dev2 不能被识别。。 可能是不需要指定 本地分支 HEAD , 只能当前分支上pull,

    D:\code\git\mw\me\umc-portal>git pull --set-upstream origin dev2
    From http://192.169.2.234/luokai/umc-portal
    * branch dev2 -> FETCH_HEAD
    Updating 912dabdd..d2cc7b50
    Fast-forward
    system/src/main/resources/readme.txt | 7 +++++++
    1 file changed, 7 insertions(+)
    create mode 100644 system/src/main/resources/readme.txt

    D:\code\git\mw\me\umc-portal>git pull origin dev2
    From http://192.169.2.234/luokai/umc-portal
    * branch dev2 -> FETCH_HEAD
    Already up to date.

    D:\code\git\mw\me\umc-portal>git pull origin dev3
    From http://192.169.2.234/luokai/umc-portal
    * branch dev3 -> FETCH_HEAD
    Already up to date.


    ---- 终于成功:
    D:\code\git\mw\me\umc-portal>git pull --set-upstream origin dev3
    From http://192.169.2.234/luokai/umc-portal
    * branch dev3 -> FETCH_HEAD
    Already up to date.

    ------ 观察 config文件:
    [branch "dev2"]
    remote = origin
    merge = refs/heads/dev
    [branch "dev4"]
    remote = origin
    merge = refs/heads/dev3

    可见, git pull --set-upstream 的作用, 基本上是 改变一个分支的 merge 头。 其他的不变。

    3个使用方式:
    1 git branch --set-upstream xx
    1 git pull --set-upstream xx
    1 git push --set-upstream upstreamName localBranchName , 在远程 upstreamName 仓库创建一个名为localBranchName的分支

    -u 就是 --set-upstream


    版权声明
    本文原创发表于 博客园,作者为 阿K .     本文欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则视为侵权。
    欢迎关注本人微信公众号:觉醒的码农,或者扫码进群:

  • 相关阅读:
    如何正确的学习?
    GitHub的使用
    freemarker
    Vue的前端路由
    推荐一个压缩图片好用的网站-tinyPNG
    纯CSS实现滚动彩虹色文字
    npm镜像源管理
    UI、UE和UX三者之间的区别?
    移动端rem布局的学习(基于一个网易云播放页面的思考)
    移动前端不得不了解的html5 head 头标签
  • 原文地址:https://www.cnblogs.com/FlyAway2013/p/15478628.html
Copyright © 2020-2023  润新知