git - git 如何将当前分支推送到另一个远程/源?

标签 git

我的 .git/config:

[remote "origin"]
    url = git@github.com:nfpyfzyf/test.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

我本地的分支机构:

                     HEAD
                     |
                 F---G  feature**current branch
                /
       C---D---E develop
      /          
 A---B  master

我现在在功能分支中,想推送到远程。当前命令是什么,是git push origin feature吗?如果我执行 git push 会发生什么?

最佳答案

要推送特定分支,请运行 git push <remote> <branch> .在您的情况下,您唯一定义的 Remote 是 origin ,并且您想推送您的 feature分支,所以使得

$ git push origin feature

“Examples” section of the git push documentation描述如果你运行 git push 会发生什么没有其他参数。

git push

Works like git push <remote>, where is the current branch’s remote (or origin, if no remote is configured for the current branch).

鉴于您问题中的配置,您的 feature分支没有配置远程,所以上面的调用等同于下一个例子。

git push origin

Without additional configuration, works like git push origin :

沿着菊花链,我们看到这等同于

git push origin :

Push “matching” branches to origin. See in the OPTIONS section above for a description of "matching" branches.

匹配分支的规则是

The special refspec : (or +: to allow non-fast-forward updates) directs git to push “matching” branches: for every branch that exists on the local side, the remote side is updated if a branch of the same name already exists on the remote side. This is the default operation mode if no explicit refspec is found (that is neither on the command line nor in any Push line of the corresponding remotes file—see below) and no push.default configuration variable is set.

在您的情况下,唯一匹配的分支是 master , 所以 git push将推送该分支并退出。

关于git - git 如何将当前分支推送到另一个远程/源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16166713/

相关文章:

git - git push 和 git pull 有什么区别?

linux - 我们可以使用 quilt 推送/添加到本地 git 存储库吗?

c# - 如何在 VS Code 中禁用 pop GitHub

Git:如何 rebase 到先前的提交

通过 .netrc 对 perl CGI 脚本进行 Git 身份验证

git - 如何重置 git 项目中的所有内容并作为一次提交推送

git - 如何在 Git 中设置默认推送存储库?

git - 仅将特定文件移动到新分支

敏捷分支工作流的 Git merge 策略

git - 我可以让 git 不 merge 文件,而只是复制新文件吗