我想在默认情况下推拉所有分支,包括新创建的分支。
我可以为它定义一个设置吗?
否则,当我在本地添加一个新分支时,我想从服务器中获取它,最简单的方法是什么?
我创建了一个具有相同名称的新分支,并试图拉,但它不起作用。要求我提供分支机构的所有远程配置。怎么设置呢?
我想在默认情况下推拉所有分支,包括新创建的分支。
我可以为它定义一个设置吗?
否则,当我在本地添加一个新分支时,我想从服务器中获取它,最简单的方法是什么?
我创建了一个具有相同名称的新分支,并试图拉,但它不起作用。要求我提供分支机构的所有远程配置。怎么设置呢?
当前回答
如果你正在将所有分支从旧的分支移动到新的回购,那么在你的本地回购中,你需要设置跟踪每个分支到现有的起源分支,然后再推送到新的回购,否则所有的起源分支都不会出现在新的起源中。通过跟踪或检出每个分支来手动执行此操作,或者使用一行代码:
for remote in `git branch -r | grep -v '\->' | grep -v master`; do git branch --track `echo $remote|sed 's=origin/=='` `echo $remote`; done
这一行命令是基于本页上其他答案的版本,但可以说更好,因为:
it correctly sets up the branch tracking, unlike some older variants of this command on this page which only supply one parameter to --track and thus each branch ends up tracking master - not good names the local branches without the prefix “origin/” which I personally don’t want - and is consistent with what happens when you checkout a branch normally. skips tracking master since that is already happening doesn’t actually checkout anything thus is fast avoids stumbling over the -> in the output of git branch -r
接下来,如果要切换原点,请替换到旧原点的链接,并指向一个新的远程。确保你先创建新的远程,使用bitbucket/github GUI,但不要添加任何文件,否则会出现合并问题。如。
git remote set-url origin git@bitbucket.org:YOUR/SOMEREPO.git
现在推。注意,第二个命令也需要推送标签:
git push -u --all origin
git push --tags origin
其他回答
要查看所有没有使用git branch -a的分支,你应该执行:
for remote in `git branch -r`; do git branch --track $remote; done
git fetch --all
git pull --all
现在你可以看到所有的分支:
git branch
要推动所有的分支试试:
git push --all
如果你正在将分支从旧的回购转移到新的回购,并且没有所有的旧回购分支都在本地,你将需要首先跟踪它们。
for remote in `git branch -r | grep -v '\->'`; do git branch --track $remote; done
然后添加新的远程回购:
git remote add bb <path-to-new-repo>
然后你可以使用这个命令来推送所有:
git push -u bb --all
或者,如果您一次没有这样做,或者只想移动本地分支,您可以使用这里其他响应中提到的git配置命令配置repo。
重要的是,其他响应只推送所有LOCAL分支。如果分支只存在于一个备用的REMOTE存储库中,那么在没有首先跟踪它们之前,它们将不会移动。这里给出的for循环将帮助解决这个问题。
对我来说,转移所有分支和标签的完整过程是,结合@vikas027和@kumarahul的答案:
~$ git clone <url_of_old_repo>
~$ cd <name_of_old_repo>
~$ git remote add new-origin <url_of_new_repo>
~$ git push new-origin --mirror
~$ git push new-origin refs/remotes/origin/*:refs/heads/*
~$ git push new-origin --delete HEAD
最后一步是因为一个名为HEAD的分支由于通配符出现在新的远程中
如果你从一个远端源推到另一个远端源,你可以使用这个:
git push newremote refs/remotes/oldremote/*:refs/heads/*
这对我很管用。参考这个:https://www.metaltoad.com/blog/git-push-all-branches-new-remote
最简单的方法是:
git push --all origin
这将推动标签和分支。