LoginSignup
0
0

【Git】GitHubの基本操作(草生やすまで)

Last updated at Posted at 2024-07-03

ローカルリポジトリを作成する

  1. ディレクトリ作成 mkdir xxx_xxxxxxxx
  2. 作成したディレクトリへ移動 cd xxx_xxxxxxxx
  3. リポジトリ作成 git init
  4. リポジトリ作成されたかの確認 ls -a
    上記コマンドで .git ディレクトリが表示されてればOK

リモートリポジトリを作成する

  1. ブラウザで自身のGitHubリポジトリに移動
  2. Repositoriesタグをクリック
  3. Newをクリック
  4. 以下の項目を入力
    Repository name:リポジトリ名を入力
  5. Privateの項目にチェックを入れる
  6. Create repositoryをクリック

リモートリポジトリとローカルのリポジトリを紐付ける

  1. 「Quick setup — if...」の文言そばにある ssh をクリック
  2. 以下のコマンドをターミナルで実行
    git remote add origin git@github.com:GitHubアカウント名/リモートリポジトリ名.git
    git branch -M main(最下部のgit push -u origin mainはまだ行わない)
  3. 紐付けができているかをgit remote -vコマンドで確認
    (以下のようなものが表示されればOK)
    origin git@github.com:GitHubアカウント名/リモートリポジトリ名.git (fetch)
    origin git@github.com:GitHubアカウント名/リモートリポジトリ名.git (fetch)

ローカルのリポジトリの内容をリモートリポジトリに反映させる

  1. git add xxxx.xxx (ワーキングツリーからステージングエリアへ)
  2. git commit -m 'xxxxx' (ステージングからローカルリポジトリへコミット。xxxxxはコミットメッセージを入力)
  3. git push -u origin main(この段階で実行。ローカルリポジトリに作成したコミットをリモートリポジトリにアップロード。)
  4. ブラウザで自身のGitHub上からリモートリポジトリに移動
  5. 内容が反映されているかを確認する
  6. 草が生える
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