リモート git リポジトリとそのすべてのブランチを新しいリモート リポジトリに移動したいと考えています。
古いリモコン =git@github.com:thunderrabbit/thunderrabbit.github.com.git
新しいリモート =git@newhub.example.net:tr/tr.newrepo.git
リモート git リポジトリとそのすべてのブランチを新しいリモート リポジトリに移動したいと考えています。
古いリモコン =git@github.com:thunderrabbit/thunderrabbit.github.com.git
新しいリモート =git@newhub.example.net:tr/tr.newrepo.git
ローカル マシンのターミナルで:
cd ~
git clone <old-remote> unique_local_name
cd unique_local_name
for remote in `git branch -r | grep -v master `; \
do git checkout --track $remote ; done
git remote add neworigin <new-remote>
git push --all neworigin
push
したがって、これらの他の回答がどれもうまく説明していないのは、Git のメカニズムを使用してすべてのリモート リポジトリのブランチを新しいリモートに移動する場合、リモートの各ブランチのローカル ブランチ バージョンが必要であるということです。
を使用git branch
して、ローカル ブランチを作成できます。これにより、ディレクトリの下にブランチ参照が作成され、.git/refs/heads/
すべてのローカル ブランチ参照が保存されます。
次にgit push
、--all
および--tags
オプション フラグを使用できます。
git push <new-remote> --all # Push all branches under .git/refs/heads
git push <new-remote> --tags # Push all tags under .git/refs/tags
--all
と--tags
は一緒に使用できないので、2 回押す必要があることに注意してください。
関連するgit push
ドキュメントは次のとおりです。
--all
プッシュする各参照に名前を付ける代わりに、下にあるすべての参照をプッシュするように指定します
refs/heads/
。--tags
refs/tags
コマンドラインで明示的にリストされたrefspecに加えて、下のすべてのrefがプッシュされます。
--mirror
--mirror
ブランチとタグ参照の両方を一度にプッシュするために使用できることにも注意してください。ただし、このフラグの問題は、 とだけでなく内の
すべての参照をプッシュすることです。これは、リモートにプッシュしたいものではない可能性があります。.git/refs/
.git/refs/heads
.git/refs/tags
たとえば、--mirror
の下にある古いリモートからリモート追跡ブランチをプッシュしたり、の副産物である.git/refs/remotes/<remote>/
などの他の参照をプッシュしたりできます。.git/refs/original/
git filter-branch
全体的なアイデアは、古いリモートブランチごとに次のことを行うことです。
そのように:
#!/bin/bash
new_remote_link=git@newhub.example.net:tr/tr.newrepo.git
new_remote=new_remote
old_remote_link=git@github.com:thunderrabbit/thunderrabbit.github.com.git
old_remote=origin
git remote add ${old_remote} ${old_remote_link}
git pull ${old_remote}
BRANCHES=`git ls-remote --heads ${old_remote} | sed 's?.*refs/heads/??'`
git remote add ${new_remote} ${new_remote_link}
for branch in ${BRANCHES}; do
git checkout ${branch}
git pull ${old_remote} ${branch}
git push ${new_remote} ${branch} --tags
printf "\nlatest %s commit\n" ${branch}
git log --pretty=format:"(%cr) %h: %s%n%n" -n1
done
origin
リポジトリの URL を変更するだけです。
git clone <old-remote-url> unique_local_name
cd unique_local_name
git pull --all
git remote set-url origin <new-remote-url>
git push --all