LoginSignup
54
57

More than 5 years have passed since last update.

[Git] リポジトリを GitHub(Public) から Bitbucket(private) に移行する方法、 remote を増やしたり減らしたりして管理を柔軟にする方法

Posted at

状況

細々とプロジェクトをすすめていて、そろそろコードを非公開にしなくちゃいけないところに来たけれど、お金がないって状況になり、無料でプライベートリポジトリを使える Bitbucket を利用することにしました。

やること

$ git remote set-url origin git@bitbucket.org/watashi/project.git
$ git push origin master --force

origin の上書きということですかね。
一応 config をチェックしました。

$ vim {PROJECT_ROOT}/.git/config
---
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = git@bitbucket.org/watashi/project.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

確かに remote の origin の url が bitbucketのものになっています。

remote の追加

今後、githubに戻すかもしれないので、一応 github も残しておきたい。

$ git remote add github git@github.com:watashi/project.git

一応 config を見てみる

$ vim {PROJECT_ROOT}/.git/config
---
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[branch "master"]
[remote "github"]
    url = git@github.com:su3/letterpress_dev.git
    fetch = +refs/heads/*:refs/remotes/github/*
[remote "origin"]
    url = git@bitbucket.org/watashi/project.git
    fetch = +refs/heads/*:refs/remotes/origin/*

remote の確認

登録された remote は以下のコマンドで確認できます。

$ git remote -v
---
github  git@github.com:watashi/project.git (fetch)
github  git@github.com:watashi/project.git (push)
origin  git@bitbucket.org/watashi/project.git (fetch)
origin  git@bitbucket.org/watashi/project.git (push)

remote の削除

やっぱいいや、いらないかな...って時は。

$ git remote rm github

ref) http://bayashi.net/diary/2012/0714

54
57
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
54
57