git config新分支的默认推送目标 [英] git config default push destination for new branches

查看:192
本文介绍了git config新分支的默认推送目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您通过以下方式创建本地存储库:

  git init 

然后如何为 git push 设置默认遥控器,因此,如果您创建新分支并希望 git push 它的提交,您不需要指定远程目标吗?



请考虑到本地存储库是



到目前为止,我仅设法为主服务器设置了远程,因为它没有被提交或分支的任何提交。是第一个分支的默认名称,但这不能解决问题,因为此时将要创建的其他分支具有未知名称。



您是否有任何配置条目

解决方案

您可以设置 push.default。

解决方案

到当前这样:

  git config push.default当前

man git-config 中进行了描述:

  push.default 
定义在没有明确指定refspec
的情况下git push应该执行的操作。不同的值非常适合特定于
的工作流程;例如,在纯粹的中央
工作流程中(即,提取源等于推送
目标),上游可能就是您想要的。可能的
值为:
(...)

current-推送当前分支以在接收端更新具有相同
名称的分支。可在中央和非中央
工作流程中使用。

要检查其工作原理,请先添加一个远程存储库,然后
将其推送到创建新的本地存储库,它甚至可以驻留在
相同的文件系统上:

  $ git remote add origin< REMOTE_REPO_ADDRESS> 

然后尝试 git push -首先使用 master 分支,然后使用 dev

  $触摸
$ git添加
$ git commit -minitial
[master(root-commit)c89b8e4]初始
1个文件已更改,0插入(+),0删除(-)
创建模式100644 a
$ git push
计数对象:3,完成。
写入对象:100%(3/3),206字节| 0字节/秒,完成。
总计3(增量0),重用0(增量0)
到/ tmp / git-init-remote-
* [new branch] master-> master
$ git checkout -b dev
切换到新分支'dev'
$ touch b
$ git add b
$ git commit -mdev
$ git push
总计0(增量0),重用0(增量0)
到/ tmp / git-init-remote-
* [新分支] dev-> dev


If you create a local repository by:

git init

Then how to set a default remote for git push so if you create a new branch and want to git push its commits you don't need to specify the remote destination?

Take into account that the local repository is not cloned form a remote and just initialized so it does not have any commits to be pushed nor branches.

so far I only managed to set the remote for the master because it is the default name for the first branch but this does not solve the problem because other branches that will be created have at this point unknown names.

Is there any config entry you can use to set default push destination for branches in this case?

解决方案

You can set push.default to current like this:

git config push.default current

It's described in man git-config:

push.default
  Defines the action git push should take if no refspec is
  explicitly given. Different values are well-suited for
  specific workflows; for instance, in a purely central
  workflow (i.e. the fetch source is equal to the push
  destination), upstream is probably what you want. Possible
  values are:
  (...)

  current - push the current branch to update a branch with the same
  name on the receiving end. Works in both central and non-central
  workflows.

To check how it works in practice first add a remote repository you will push to after creating a new local repository, it can even reside on the same filesystem:

$ git remote add origin <REMOTE_REPO_ADDRESS>

and then try git push - first with master branch and then with dev:

$ touch a
$ git add a
$ git commit -minitial
[master (root-commit) c89b8e4] initial
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a
$ git push
Counting objects: 3, done.
Writing objects: 100% (3/3), 206 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To /tmp/git-init-remote-
 * [new branch]      master -> master
$ git checkout -b dev
Switched to a new branch 'dev'
$ touch b
$ git add b
$ git commit -mdev
$ git push
Total 0 (delta 0), reused 0 (delta 0)
To /tmp/git-init-remote-
 * [new branch]      dev -> dev

这篇关于git config新分支的默认推送目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆