Skip to content

Instantly share code, notes, and snippets.

@ishidur
Last active September 11, 2018 05:46
Show Gist options
  • Save ishidur/898f36a8fd20821a0511ff84fb9cc5ed to your computer and use it in GitHub Desktop.
Save ishidur/898f36a8fd20821a0511ff84fb9cc5ed to your computer and use it in GitHub Desktop.
git remote関連 あれこれ #git #shell

mirrorオプションでGitHubへリポジトリを移行する

git clone --mirror [email protected]:/path/to/PrivateProject.git
git remote set-url --push origin [email protected]:Taro/PublicProject.git
git push --mirror

--mirror オプションを使用しない手順

移行元のリポジトリをcloneする

git clone [email protected]:/path/to/PrivateProject.git

移行元のリポジトリからすべてのリモートブランチをローカルにチェックアウトする

git branch -a | grep -v HEAD | perl -ne 'chomp($_); s|^\*?\s*||; if (m|(.+)/(.+)| && not $d{$2}) {print qq(git branch --track $2 $1/$2\n)} else {$d{$_}=1}' | bash

push/fetch先を変更する例

git remote rm origin
git remote add origin [email protected]:Taro/PublicProject.git

GitHubリポジトリを別名で追加する

git remote add github [email protected]:Taro/PublicProject.git
git remote -v

ローカルにあるブランチとタグをpushする

git push origin --all
git push origin --tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment