LoginSignup
0
0

More than 5 years have passed since last update.

既存のリモートリポジトリURLを新規作成したリポジトリのURLに変更する方法

Posted at

はじめに

この記事は、既存のリモートリポジトリからGitCloneする時に、新規作成したリポジトリのURLに変更する方法について書いたものです。

例えば、学習やコードリーディング用に他の人が作成したリポジトリを自分なりに色々といじりたいと思ったことってありません?

そのままクローンしてローカルでいじるだけでもいいんですが、せっかくだったらPushして自分の作業履歴をバージョン管理したいですよね。

この記事が少しでもお役に立てたら嬉しいです。

対象となる読者

  • Gitコマンドについて基礎的な理解ができている人
  • Githubへすでにアカウント登録している人

新規リポジトリの作成

まずはGitHubのページから、New Repositoryを選択し、新規リポジトリを作成します。

new-repository.png

Repository nameに任意のリポジトリ名を入力します。

new-repository-002.png

問題がなければCreate Repositoryを押下しましょう。

new-repository-003.png

push an existing repository from the command lineにあるコマンドを使うので、ブラウザを開いたままにしておきます。

new-repository-004.png

# 新規作成したリモートリポジトリのURL
git remote add origin git@github.com:yuta-ushijima/sample.git
git push -u origin master

ローカルでの作業

ここからはローカルでターミナルを使った作業になります。

まずは、現在のプロジェクトのリモート情報を以下のコマンドで確認しましょう。

git remote -v

次のような結果が返ってきます。

origin  git@github.com:StephenGrider/ReduxSimpleStarter.git (fetch)
origin  git@github.com:StephenGrider/ReduxSimpleStarter.git (push)

上記の情報を新規リポジトリのリモート情報に書き換えます。

git remote set-url origin git@github.com:yuta-ushijima/sample.git

書き換わったかどうか、もう一度git remote -vで確認してみましょう。

git remote -v

次のような結果が返ってので、ちゃんとリモート先が変更されているのが確認できます。


origin  git@github.com:yuta-ushijima/sample.git (fetch)
origin  git@github.com:yuta-ushijima/sample.git (push)

この状態でgit statusで差分を確認して見ましょう。

git status

何かしらの差分が出ているはずです。人によってはステージング前かもしれませんし、commit直前かもしれません。

On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   package-lock.json

no changes added to commit (use "git add" and/or "git commit -a")

あとはそのままpushすれば、ブラウザの画面を更新すると、先ほどpushしたcommitが反映されているはずです。

0
0
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
0
0