我有两个远程库:upstream和origin。upstream是我无法推送到的,而origin则是我的自己的存储库。如何从upstream获取所有分支,然后将它们推送到origin? 我尝试过:
git fetch upstream
git push --all origin
但它不起作用。
我只需要将一个Bitbucket仓库复制到GitHub上,以下是步骤,假设您的远程仓库名为origin,所有分支和标签都将被复制:
git remote add neworigin url-to-new-remote
git push neworigin --tags "refs/remotes/origin/*:refs/heads/*"
好的一点是,这样您工作副本中的文件不会被修改。
--force
吗?或者加上 --tags
来包含它们? - David Tchepakzsh: no matches found: refs/remotes/origin/*:refs/heads/*
,直到我将refspec放在引用符中,例如""refs/remotes/origin/*:refs/heads/*"
。 - Stefano你可以尝试使用--mirror
选项克隆上游代码库,然后再使用--mirror
选项将其推送到新的远程代码库中。
你将拥有以下流程:
git clone <upstream-repo-url/repo.git> --mirror
cd <repo>
git remote add <your-remote-name> <your-remote-url/repo.git>
git push <your-remote-name> --mirror
请注意,push --mirror
命令会删除在你的 <your-remote-name>
上的分支,请谨慎操作。
fatal: not a git repository (or any parent up to mount point /)
。 - Toby 1 Kenobicd
命令。 - Toby 1 Kenobi将一个(裸的)仓库完全克隆到另一个(裸的)仓库,包括所有分支,而不仅仅是已检出的分支的完整答案是通过克隆本地裸仓库作为中间件来实现。然后,在克隆的过程中,所有分支都会被拉取,并且使用 git push --all 命令可以将它们全部推送。以下示例在 Windows 上从 github 到 gitlab 执行:
结果:25 个分支被推送到 gitlab。
注意,对于所有分支来说,都不需要 git checkout 命令,因为它对于裸仓库也没有意义。
--force
,除非你绝对确定需要它。否则这正是我在寻找的! - Lars Nyström当你执行git push <REMOTE> --all
或者git push <REMOTE> --tags
时,所有的分支和标签都将从你的本地历史推送到远程仓库。如果你想要把一个远程仓库(比如origin)中的所有分支和标签(不仅仅是你的本地历史)推送到另一个远程仓库(比如upstream),请按照以下步骤进行操作:
git fetch --prune
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git remote add upstream <the-url-path-of-a-remote.git>
push
all of the branches and tags to the new remote:
git push --all upstream
git push --tags upstream
git fetch --prune
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git remote add upstream <the-url-path-of-a-remote.git>
git push --all upstream
git push --tags upstream
mkdir migrate
git clone $1 migrate
cd migrate
git fetch origin
git remote add new-origin $2
git push -u new-origin --all
git push new-origin --tags
git remote set-head origin -d
git push new-origin refs/remotes/origin/*:refs/heads/*
git fetch -pPt upstream
git push origin --tags "refs/remotes/upstream/*:refs/heads/*"
--tags
选项。git remote add your-new-origin url-to-repo/repo.git
git push --all your-new-origin //pushes all branches
git push --tags your-new-origin //pushes all tags