我想在默认情况下推拉所有分支,包括新创建的分支。
我可以为它定义一个设置吗?
否则,当我在本地添加一个新分支时,我想从服务器中获取它,最简单的方法是什么?
我创建了一个具有相同名称的新分支,并试图拉,但它不起作用。要求我提供分支机构的所有远程配置。怎么设置呢?
我想在默认情况下推拉所有分支,包括新创建的分支。
我可以为它定义一个设置吗?
否则,当我在本地添加一个新分支时,我想从服务器中获取它,最简单的方法是什么?
我创建了一个具有相同名称的新分支,并试图拉,但它不起作用。要求我提供分支机构的所有远程配置。怎么设置呢?
当前回答
我在这里找到了最好和最简单的方法,就像@kumarahul张贴的那样,对我来说很有魅力,它会把所有的标签和分支从原点推送到新的遥控器:
git remote add newremote new-remote-url
git push newremote --tags refs/remotes/origin/*:refs/heads/*
我使用'git push——all -u newremote',但它只会将检出的分支推到newremote。
Git: Push All Branches to a New Remote by Keith Dechant , Software Architect Here's a scenario some of you might have encountered with your Git repositories. You have a working copy of a Git repo, say from an old server. But you only have the working copy, and the origin is not accessible. So you can't just fork it. But you want to push the whole repo and all the branch history to your new remote. This is possible if your working copy contains the tracking branches from the old remote (origin/branch1, origin/branch1, etc.). If you do, you have the entire repo and history. However, in my case there were dozens of branches, and some or all of them I had never checked out locally. Pushing them all seemed like a heavy lift. So, how to proceed? I identified two options: Option 1: Checkout every branch and push I could do this, and I could even write a Bash script to help. However, doing this would change my working files with each checkout, and would create a local branch for each of the remote tracking branches. This would be slow with a large repo. Option 2: Push without changing your working copy There is a second alternative, which doesn't require a checkout of each branch, doesn't create extraneous branches in the working copy, and doesn't even modify the files in the working copy. If your old, no-longer-active remote is called "oldremote" and your new remote is called "newremote", you can push just the remote tracking branches with this command: git push newremote refs/remotes/oldremote/*:refs/heads/* In some cases, it's also possible to push just a subset of the branches. If the branch names are namespaced with a slash (e.g., oldremote/features/branch3, oldremote/features/branch4, etc.), you can push only the remote tracking branches with names beginning with "oldremote/features": git push newremote refs/remotes/oldremote/features/*:refs/heads/features/* Whether you push all the branches or just some of them, Git will perform the entire operation without creating any new local branches, and without making changes to your working files. Every tracking branch that matches your pattern will be pushed to the new remote. For more information on the topic, check out this thread on Stack Overflow. Date posted: October 9, 2017
其他回答
如果你从一个远端源推到另一个远端源,你可以使用这个:
git push newremote refs/remotes/oldremote/*:refs/heads/*
这对我很管用。参考这个:https://www.metaltoad.com/blog/git-push-all-branches-new-remote
在推送规范中包含+可能是一个坏主意,因为这意味着即使没有-f, git也会很乐意执行非快进推送,如果远程服务器设置为接受这些,则可能会丢失历史记录。
试试这个:
$ git config --add remote.origin.push 'refs/heads/*:refs/heads/*'
$ git config --add remote.origin.push 'refs/tags/*:refs/tags/*'
$ git config --add remote.origin.fetch 'refs/heads/*:refs/remotes/origin/*'
$ git config --add remote.origin.fetch 'refs/tags/*:refs/tags/*'
我在这里找到了最好和最简单的方法,就像@kumarahul张贴的那样,对我来说很有魅力,它会把所有的标签和分支从原点推送到新的遥控器:
git remote add newremote new-remote-url
git push newremote --tags refs/remotes/origin/*:refs/heads/*
我使用'git push——all -u newremote',但它只会将检出的分支推到newremote。
Git: Push All Branches to a New Remote by Keith Dechant , Software Architect Here's a scenario some of you might have encountered with your Git repositories. You have a working copy of a Git repo, say from an old server. But you only have the working copy, and the origin is not accessible. So you can't just fork it. But you want to push the whole repo and all the branch history to your new remote. This is possible if your working copy contains the tracking branches from the old remote (origin/branch1, origin/branch1, etc.). If you do, you have the entire repo and history. However, in my case there were dozens of branches, and some or all of them I had never checked out locally. Pushing them all seemed like a heavy lift. So, how to proceed? I identified two options: Option 1: Checkout every branch and push I could do this, and I could even write a Bash script to help. However, doing this would change my working files with each checkout, and would create a local branch for each of the remote tracking branches. This would be slow with a large repo. Option 2: Push without changing your working copy There is a second alternative, which doesn't require a checkout of each branch, doesn't create extraneous branches in the working copy, and doesn't even modify the files in the working copy. If your old, no-longer-active remote is called "oldremote" and your new remote is called "newremote", you can push just the remote tracking branches with this command: git push newremote refs/remotes/oldremote/*:refs/heads/* In some cases, it's also possible to push just a subset of the branches. If the branch names are namespaced with a slash (e.g., oldremote/features/branch3, oldremote/features/branch4, etc.), you can push only the remote tracking branches with names beginning with "oldremote/features": git push newremote refs/remotes/oldremote/features/*:refs/heads/features/* Whether you push all the branches or just some of them, Git will perform the entire operation without creating any new local branches, and without making changes to your working files. Every tracking branch that matches your pattern will be pushed to the new remote. For more information on the topic, check out this thread on Stack Overflow. Date posted: October 9, 2017
解决方案没有硬编码的配置来源
在全局gitconfig中使用以下命令
[remote]
push = +refs/heads/*
push = +refs/tags/*
这将推送所有分支和所有标签
为什么你不应该硬编码的来源配置?
如果你硬编码:
你最终会在所有的回购中使用origin作为遥控器。你不能添加origin,你需要使用set-url。 如果一个工具用不同的名称创建了一个远程,则push all配置将不应用。然后你将不得不重命名远程,但重命名将不起作用,因为原点已经存在(从点1)记住:)
现代git已经在处理抓取了
美国每年Jakub刚纳ębski的答案:
使用现代git,你总是获取所有分支(作为远程跟踪分支)到refs/remotes/origin/*命名空间
首先将远程git添加到您的loacl with中
git remote add remote_name remote_address
而之后你只需要用下面的命令就可以了
git push --all remote_name