[git]remote addでリポジトリを追加する方法とは?ヘルプ表示や変更する方法についても紹介
![[git]remote addでリポジトリを追加する方法とは?ヘルプ表示や変更する方法についても紹介](/infla/column/wp-content/uploads/2022/05/f3cf84bdcc2c736a6c36484d63b04633.jpg)
[git]remote addでリポジトリを追加しよう!
今回は、git remoteコマンドの使い方について説明します。gitはリポジトリを使ってソースなどのファイルのバージョン管理をします。リポジトリにはローカルリポジトリとリモートリポジトリが存在します。ここでは、リモートリポジトリを管理する方法を紹介します。gitのバージョンは以下とします。
1
2
|
~$ git --version
git version 2.25.1
|
興味のある方はぜひご覧ください。
ヘルプ表示
まず、GitHubからgit cloneコマンドでcloneします。ここでは、「test」というリポジトリを利用します。
1
2
3
4
5
6
7
8
9
|
~$ git clone git@github.com:{GitHubユーザ名}/test.git
Cloning into 'test'...
The authenticity of host 'github.com (52.192.72.89)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,52.192.72.89' (RSA) to the list of known hosts.
Enter passphrase for key '/home/user/.ssh/id_rsa':
warning: You appear to have cloned an empty repository.
~$ cd test/
|
git remoteまたは、git remote addコマンドはhオプションでヘルプが表示できます。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
~/test$ git remote -h
usage: git remote [-v | --verbose]
or: git remote add [-t <branch>] [-m <master>] [-f] [--tags | --no-tags] [--mirror=<fetch|push>] <name> <url>
or: git remote rename <old> <new>
or: git remote remove <name>
or: git remote set-head <name> (-a | --auto | -d | --delete | <branch>)
or: git remote [-v | --verbose] show [-n] <name>
or: git remote prune [-n | --dry-run] <name>
or: git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]
or: git remote set-branches [--add] <name> <branch>...
or: git remote get-url [--push] [--all] <name>
or: git remote set-url [--push] <name> <newurl> [<oldurl>]
or: git remote set-url --add <name> <newurl>
or: git remote set-url --delete <name> <url>
-v, --verbose be verbose; must be placed before a subcommand
|
1
2
3
4
5
6
7
8
9
10
11
|
~/test$ git remote add -h
usage: git remote add [<options>] <name> <url>
-f, --fetch fetch the remote branches
--tags import all tags and associated objects when fetching
or do not fetch any tag at all (--no-tags)
-t, --track <branch> branch(es) to track
-m, --master <branch>
master branch
--mirror[=(push|fetch)]
set up remote as a mirror to push to or fetch from
|
リモートリポジトリの一覧表示
git remoteコマンドで、現在登録されているリモートの一覧を表示できます。
1
2
3
4
5
6
|
~/test$ git remote
origin
~/test$ git remote -v
origin git@github.com:{GitHubユーザ名}/test.git (fetch)
origin git@github.com:{GitHubユーザ名}/test.git (push)
~/test$
|
リモートリポジトリの追加
git remote addコマンドで、リモートリポジトリを追加できます。
1
2
3
4
5
6
7
8
9
10
|
~/test$ git remote add develop git@github.com:{GitHubユーザ名}/test.git
~/test$ git remote
develop
origin
~/test$ git remote -v
develop git@github.com:{GitHubユーザ名}/test.git (fetch)
develop git@github.com:{GitHubユーザ名}/test.git (push)
origin git@github.com:{GitHubユーザ名}/test.git (fetch)
origin git@github.com:{GitHubユーザ名}/test.git (push)
~/test$
|
リモートリポジトリの削除
git remote removeコマンドで、リモートリポジトリを削除できます。
1
2
3
4
5
6
7
|
~/test$ git remote remove develop
~/test$ git remote
origin
~/test$ git remote -v
origin git@github.com:{GitHubユーザ名}/test.git (fetch)
origin git@github.com:{GitHubユーザ名}/test.git (push)
~/test$
|
リモートリポジトリの変更
git remote renameコマンドで、リモートリポジトリを変更できます。変更前は以下の状態とします。
1
2
3
4
5
6
7
8
9
|
~/test$ git remote
develop
origin
~/test$ git remote -v
develop git@github.com:{GitHubユーザ名}/test.git (fetch)
develop git@github.com:{GitHubユーザ名}/test.git (push)
origin git@github.com:{GitHubユーザ名}/test.git (fetch)
origin git@github.com:{GitHubユーザ名}/test.git (push)
~/test$
|
以下のコマンドでリモートリポジトリを変更できます。
1
2
3
4
5
6
7
8
9
10
|
~/test$ git remote rename develop feature
~/test$ git remote
feature
origin
~/test$ git remote -v
feature git@github.com:{GitHubユーザ名}/test.git (fetch)
feature git@github.com:{GitHubユーザ名}/test.git (push)
origin git@github.com:{GitHubユーザ名}/test.git (fetch)
origin git@github.com:{GitHubユーザ名}/test.git (push)
~/test$
|
リモートリポジトリの情報表示
git remote showコマンドで、リモートリポジトリの情報が表示できます。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
~/test$ git remote show origin
Warning: Permanently added the RSA host key for IP address '52.69.186.44' to the list of known hosts.
Enter passphrase for key '/home/user/.ssh/id_rsa':
* remote origin
Fetch URL: git@github.com:{GitHubユーザ名}/test.git
Push URL: git@github.com:{GitHubユーザ名}/test.git
HEAD branch: (unknown)
Local branch configured for 'git pull':
master merges with remote master
~/test$ git remote show feature
Warning: Permanently added the RSA host key for IP address '13.114.40.48' to the list of known hosts.
Enter passphrase for key '/home/user/.ssh/id_rsa':
* remote feature
Fetch URL: git@github.com:{GitHubユーザ名}/test.git
Push URL: git@github.com:{GitHubユーザ名}/test.git
HEAD branch: (unknown)
~/test$
|
リモートリポジトリのURL取得・設定
git remote get-urlコマンドで、リモートリポジトリのURLを取得できます。
1
2
3
|
~/test$ git remote get-url origin
git@github.com:{GitHubユーザ名}/test.git
~/test$
|
git remote set-urlコマンドで、リモートリポジトリのURLを設定できます。
1
|
~/test$ git remote set-url origin git@github.com:{GitHubユーザ名}/test.git
|
まとめ
いかがでしたでしょうか。gitリポジトリにはローカルリポジトリとリモートリポジトリが存在します。ここでは、リモートリポジトリを管理する方法を紹介しました。
ぜひご自身でコマンドを打って、理解を深めてください。
ネプラス株式会社はサービス開始から10年以上
『エンジニアの生涯価値の向上』をミッションに掲げ、
多くのインフラエンジニア・ネットワークエンジニアの就業を支援してきました。
ネプラス株式会社はこんな会社です
秋葉原オフィスにはネプラス株式会社をはじめグループのIT企業が集結!
数多くのエンジニアが集まります。

-
インフラ業界に特化
ネットワーク・サーバー・データベース等、ITインフラ業界に特化。Cisco Systemsプレミアパートナーをはじめ各種ベンダーのパートナー企業です。
業界を知り尽くしているからこそ大手の取引先企業、経験豊富なエンジニアに選ばれています。
-
正社員なのにフリーランスのような働き方
正社員の方でも希望を聞いたうえでプロジェクトをアサインさせていただいており、フリーランスのような働き方が可能。帰社日もありません。
プロジェクト終了後もすぐに次の案件をご紹介させていただきますのでご安心ください。
-
大手直取引の高額案件
案件のほとんどが大手SIerやエンドユーザーからの直取引のためエンジニアの皆様へに高く還元できています。
Ciscoをはじめ、Juniper、Azure、Linux、AWS等インフラに特化した常時300件以上の案件があります。
-
スキルアップ支援
不要なコストを削減し、その分エンジニアの方へのスキルアップ支援(ネットワーク機器貸出、合格時の受験費用支給など)や給与で還元しています。
受験費用例)CCNP,CCIE:6-20万円、JNCIS:3-4万円、AWS:1-3万円など
※業務に関連する一定の資格のみ。各種条件がありますので詳しくは担当者へにお尋ねください。
-
現給与を保証します!※
前職の給与保証しており、昨年度は100%の方が給与アップを実現。収入面の不安がある方でも安心して入社していただけます。
※適用にはインフラエンジニアの業務経験1年以上、等一定の条件がございます。
-
インセンティブ制度
ネットワーク機器の販売・レンタル事業等、売上に貢献いただいた方にはインセンティブをお支払いしています。
取引先企業とエンジニア側、双方にメリットがあり大変好評をいただいています。
-
社会保険・福利厚生
社員の方は、社会保険を完備。健康保険は業界内で最も評価の高い「関東ITソフトウェア健康保険組合」です。
さらに様々なサービスをお得に利用できるベネフィットステーションにも加入いただきます。
-
東証プライム上場企業グループ
ネプラスは東証プライム上場「株式会社オープンアップグループ」のグループ企業です。
安定した経営基盤とグループ間のスムーズな連携でコロナ禍でも安定した雇用を実現させています。
ネプラス株式会社に興味を持った方へ
ネプラス株式会社では、インフラエンジニアを募集しています。
年収をアップしたい!スキルアップしたい!大手の上流案件にチャレンジしたい!
オンライン面接も随時受付中。ぜひお気軽にご応募ください。

