1
0
mirror of synced 2026-01-07 18:01:41 -05:00
Files
docs/translations/ja-JP/content/get-started/importing-your-projects-to-github/importing-source-code-to-github/adding-locally-hosted-code-to-github.md
docubot 68fb49057c New translation batch for ja (#30339)
Co-authored-by: Hector Alfaro <hectorsector@github.com>
2022-08-29 11:17:03 +00:00

13 KiB
Raw Blame History

title, intro, redirect_from, versions, shortTitle
title intro redirect_from versions shortTitle
Adding locally hosted code to GitHub Learn how to add existing source code or repositories to {% data variables.product.product_name %} from the command line using {% data variables.product.prodname_cli %} or Git Commands. Then, share your code and invite others to work with you.
/articles/add-an-existing-project-to-github
/articles/adding-an-existing-project-to-github-using-the-command-line
/github/importing-your-projects-to-github/adding-an-existing-project-to-github-using-the-command-line
/github/importing-your-projects-to-github/importing-source-code-to-github/adding-an-existing-project-to-github-using-the-command-line
/get-started/importing-your-projects-to-github/importing-source-code-to-github/adding-an-existing-project-to-github-using-the-command-line
fpt ghes ghae ghec
* * * *
Add locally hosted code

About adding existing source code to {% data variables.product.product_name %}

If you have existing source code or repositories stored locally on your computer or private network you can add them to {% data variables.product.product_name %} by typing commands in a terminal. You can do this by typing Git commands directly, or by using {% data variables.product.prodname_cli %}.

{% data variables.product.prodname_cli %} は、コンピューターのコマンドラインから {% data variables.product.prodname_dotcom %} を使用するためのオープンソースツールです。 {% data variables.product.prodname_cli %} can simplify the process of adding an existing project to {% data variables.product.product_name %} using the command line. {% data variables.product.prodname_cli %}についてさらに学ぶには、「{% data variables.product.prodname_cli %}について」を参照してください。

{% tip %}

ヒント: ポイントアンドクリック型のユーザインターフェースに慣れている場合は、プロジェクトを {% data variables.product.prodname_desktop %}で追加してみてください。 詳しい情報については {% data variables.product.prodname_desktop %}ヘルプ 中のローカルコンピュータから GitHub Desktop へのリポジトリの追加を参照してください。

{% endtip %}

{% data reusables.repositories.sensitive-info-warning %}

Adding a local repository to {% data variables.product.product_name %} with {% data variables.product.prodname_cli %}

  1. In the command line, navigate to the root directory of your project.

  2. ローカルディレクトリを Git リポジトリとして初期化します。

    git init -b main
    
  3. Stage and commit all the files in your project

    git add . && git commit -m "initial commit"
    
  4. To create a repository for your project on GitHub, use the gh repo create subcommand. When prompted, select Push an existing local repository to GitHub and enter the desired name for your repository. If you want your project to belong to an organization instead of your user account, specify the organization name and project name with organization-name/project-name.

  5. Follow the interactive prompts. To add the remote and push the repository, confirm yes when asked to add the remote and push the commits to the current branch.

  6. Alternatively, to skip all the prompts, supply the path to the repository with the --source flag and pass a visibility flag (--public, --private, or --internal). For example, gh repo create --source=. --public. Specify a remote with the --remote flag. To push your commits, pass the --push flag. For more information about possible arguments, see the GitHub CLI manual.

Adding a local repository to {% data variables.product.product_name %} using Git

{% mac %}

  1. {% data variables.product.product_location %}上で新しいリポジトリを作成します。 エラーを避けるため、新しいリポジトリはREADME、ライセンス、あるいは gitignore で初期化しないでください。 これらのファイルは、プロジェクトを {% data variables.product.product_name %}にプッシュした後で追加できます。 [Create New Repository] ドロップダウン {% data reusables.command_line.open_the_multi_os_terminal %}

  2. ワーキングディレクトリをローカルプロジェクトに変更します。

  3. Use the init command to initialize the local directory as a Git repository. By default, the initial branch is called master.

    If youre using Git 2.28.0 or a later version, you can set the name of the default branch using -b.

    $ git init -b main
    

    If youre using Git 2.27.1 or an earlier version, you can set the name of the default branch using && git branch -m.

    $ git init && git branch -m main
    
  4. ファイルを新しいローカルリポジトリに追加します。 これで、それらのファイルが最初のコミットに備えてステージングされます。

$ git add .
# ローカルリポジトリにファイルを追加し、コミットに備えてステージします。 {% data reusables.git.unstage-codeblock %}
  1. ローカルリポジトリでステージングしたファイルをコミットします。
$ git commit -m "First commit"
# 追跡された変更をコミットし、リモートリポジトリへのプッシュに備えます。 {% data reusables.git.reset-head-to-previous-commit-codeblock %}
  1. At the top of your repository on {% ifversion ghae %}{% data variables.product.product_name %}{% else %}{% data variables.product.product_location %}{% endif %}'s Quick Setup page, click {% octicon "clippy" aria-label="The copy to clipboard icon" %} to copy the remote repository URL. リモートリポジトリの URL フィールドのコピー
  2. ターミナルで、ローカルリポジトリがプッシュされるリモートリポジトリの URL を追加してください。
$ git remote add origin <em> &lt;REMOTE_URL> </em>
# 新しいリモートを設定する
$ git remote -v
# 新しいリモート URL を検証する
  1. {% data variables.product.product_location %} へ、ローカルリポジトリの変更をプッシュします。
$ git push -u origin main
# ローカルリポジトリの変更を、origin として指定したリモートリポジトリにプッシュする

{% endmac %}

{% windows %}

  1. {% data variables.product.product_location %}上で新しいリポジトリを作成します。 エラーを避けるため、新しいリポジトリはREADME、ライセンス、あるいは gitignore で初期化しないでください。 これらのファイルは、プロジェクトを {% data variables.product.product_name %}にプッシュした後で追加できます。 [Create New Repository] ドロップダウン {% data reusables.command_line.open_the_multi_os_terminal %}

  2. ワーキングディレクトリをローカルプロジェクトに変更します。

  3. Use the init command to initialize the local directory as a Git repository. By default, the initial branch is called master.

    If youre using Git 2.28.0 or a later version, you can set the name of the default branch using -b.

    $ git init -b main
    

    If youre using Git 2.27.1 or an earlier version, you can set the name of the default branch using && git branch -m.

    $ git init && git branch -m main
    
  4. ファイルを新しいローカルリポジトリに追加します。 これで、それらのファイルが最初のコミットに備えてステージングされます。

$ git add .
# ローカルリポジトリにファイルを追加し、コミットに備えてステージします。 {% data reusables.git.unstage-codeblock %}
  1. ローカルリポジトリでステージングしたファイルをコミットします。
$ git commit -m "First commit"
# 追跡された変更をコミットし、リモートリポジトリへのプッシュに備えます。 {% data reusables.git.reset-head-to-previous-commit-codeblock %}
  1. At the top of your repository on {% ifversion ghae %}{% data variables.product.product_name %}{% else %}{% data variables.product.product_location %}{% endif %}'s Quick Setup page, click {% octicon "clippy" aria-label="The copy to clipboard icon" %} to copy the remote repository URL. リモートリポジトリの URL フィールドのコピー
  2. コマンドプロンプトで、ローカルリポジトリのプッシュ先となるリモートリポジトリの URL を追加します。
$ git remote add origin <em> &lt;REMOTE_URL> </em>
# 新しいリモートを設定する
$ git remote -v
# 新しいリモート URL を検証する
  1. {% data variables.product.product_location %} へ、ローカルリポジトリの変更をプッシュします。
$ git push origin main
# ローカルリポジトリの変更を、origin として指定したリモートリポジトリにプッシュする

{% endwindows %}

{% linux %}

  1. {% data variables.product.product_location %}上で新しいリポジトリを作成します。 エラーを避けるため、新しいリポジトリはREADME、ライセンス、あるいは gitignore で初期化しないでください。 これらのファイルは、プロジェクトを {% data variables.product.product_name %}にプッシュした後で追加できます。 [Create New Repository] ドロップダウン {% data reusables.command_line.open_the_multi_os_terminal %}

  2. ワーキングディレクトリをローカルプロジェクトに変更します。

  3. Use the init command to initialize the local directory as a Git repository. By default, the initial branch is called master.

    If youre using Git 2.28.0 or a later version, you can set the name of the default branch using -b.

    $ git init -b main
    

    If youre using Git 2.27.1 or an earlier version, you can set the name of the default branch using && git branch -m.

    $ git init && git branch -m main
    
  4. ファイルを新しいローカルリポジトリに追加します。 これで、それらのファイルが最初のコミットに備えてステージングされます。

$ git add .
# ローカルリポジトリにファイルを追加し、コミットに備えてステージします。 {% data reusables.git.unstage-codeblock %}
  1. ローカルリポジトリでステージングしたファイルをコミットします。
$ git commit -m "First commit"
# 追跡された変更をコミットし、リモートリポジトリへのプッシュに備えます。 {% data reusables.git.reset-head-to-previous-commit-codeblock %}
  1. At the top of your repository on {% ifversion ghae %}{% data variables.product.product_name %}{% else %}{% data variables.product.product_location %}{% endif %}'s Quick Setup page, click {% octicon "clippy" aria-label="The copy to clipboard icon" %} to copy the remote repository URL. リモートリポジトリの URL フィールドのコピー
  2. ターミナルで、ローカルリポジトリがプッシュされるリモートリポジトリの URL を追加してください。
$ git remote add origin <em> &lt;REMOTE_URL> </em>
# 新しいリモートを設定する
$ git remote -v
# 新しいリモート URL を検証する
  1. {% data variables.product.product_location %} へ、ローカルリポジトリの変更をプッシュします。
$ git push origin main
# ローカルリポジトリの変更を、origin として指定したリモートリポジトリにプッシュする

{% endlinux %}

参考リンク