0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Gitの基本

Posted at

Gitの初期設定

名前とメールアドレスを設定する

$ git config --global user.name '名前'
$ git config --global user.email 'メールアドレス'

Gitの設定確認

$ cat ~/. gitconfig

Gitのマニュアルを表示する

$ man git

コミットができる

1.ローカルリポジトリ作成→GitHubへ追加・管理する方法

ローカルリポジトリの新規作成

$ git init

   ←.gitディレクトリが作成された

変更をステージする

$ git add -A(ファイル名)

 -Aまたは.:すべてのファイルをインデックスに登録する

リモートリポジトリ先URLを確認する

$ git remote -v

リモートリポジトリ先URLを指定する

$ git remote add origin リモートリポジトリURL

リポジトリに変更履歴を記録する(コミットする)

$ git commit -m '変更履歴や内容'

リモートリポジトリへ変更を送る(プッシュする)

$ git push -u origin main
  • -u:次回から省略できる

2.GitHubで編集した内容をローカルリポジトリへ反映させる

  • 反映させたいフォルダへ移動する
  • リモートとローカルリポジトリ *の位置を確認し、
    *mainがリモート側になっていることを確認する
  • pullでローカルリポジトリに変更が上書きされる
$ cd
$ git branch -a
  *main
  
$ git pull (-u指定あるため省略)

3.GitHub→ローカル上にダウンロードして編集する方法

  • cdでダウンロードするローカルファイルまで移動する
  • リモートリポジトリをダウンロードする 
$ cd
$ git clone リモートリポジトリURL(HTTP)

その他コマンド

変更状況を確認する

$ git log

ワークツリーの変更を元に戻す/取り消す

$ git restore .(ファイル名)
  • -staged:ステージ(インデックス)からワークツリーへ

コミットを取り消す

$ git revert 

状態を確認する

$ git status

差分を表示する

$ git diff

GitHub を使って開発を進めることができる

リモートのブランチをローカルのブランチに反映させる

$ git pull origin main

-uの設定がされていれば、origin mainは不要。

ブランチを利用して開発を進めることができる

ブランチ一覧を表示する

$ git branch

新しいブランチを作成する

$ git branch ブランチ名

ブランチを切り替える

$ git switch 移動先ブランチ名

①ブランチの切り替えを確認すると......

$ git branch 
*feature-name
  main

②feature-nameブランチをマージする
 別のブランチに変更を取り込むこと

$ git merge マージするブランチ名

③ブランチを削除する
 マージ後、分岐していたfeature-nameブランチが不要になるため削除する。

$ git branch -d feature-name

GitHub フローに従って開発を進める

プルリクエストとは 

自分の変更したコードをリポジトリに取り込んでもらえるよう依頼する機能のこと


[参考動画]だれでもエンジニア / 山浦清透:Gitの基本コマンドまとめ【Git入門講座#3】

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?