LoginSignup
1
1

More than 1 year has passed since last update.

Git 基本コマンドまとめ(Git初心者に教えるチートシート)

Last updated at Posted at 2021-02-17

1. Gitとは

参考図書:わかばちゃん
https://next.rikunabi.com/journal/tag/webdesign-manga/

2. GitをPCに導入しよう

3. リモートリポジトリをクローンする

※リポジトリはもう作ってある前提

git clone <repository> <directory>
  • repository...SSHのURL
  • directory...ローカルに作成されるフォルダ名

4. ファイルをコミットする

4-1.編集して、状況確認。編集したファイル一覧が出る

git status

modified: ...変更
new file: ...新規ファイル

4-2.ステージする

git add <file>
git add . (全ファイル)

4-3.コミットする

git commit -m "<コメント>"

5. リモートリポジトリにプッシュする

git push origin <branchname>

6. リモートリポジトリからプルする

原理:https://next.rikunabi.com/journal/20170120_t12_iq/
https://backlog.com/ja/git-tutorial/intro/16/

git pull origin <branchname>

7. ブランチを作成する

7-1. ブランチとは:

https://backlog.com/ja/git-tutorial/stepup/01/
分岐点を作ることができる

7-2. ブランチはフォルダのようなもの

  • masterブランチ ... 本番に反映したフォルダ
  • developブランチ...開発してチェック済みなフォルダ
  • featureブランチ...個人で開発するフォルダ

マージ...featureをdevelopに上書きする

ブランチの作成

git branch <branchname>
ブランチの移動
git checkout <branchname>
ブランチを作ってそこに移動
git checkout -b <branch>
リモートのブランチをコピーしてきてそこに移動(developブランチの場合)
git checkout -b develop origin/develop

8. コミット を課題に紐付ける

※コミットのコメントに課題のキーを貼り付けるだけ(Backlogの場合)

9. プルリクエストの作成と、レビューと、画面上からマージ

https://backlog.com/ja/git-tutorial/pull-request/06/
https://backlog.com/ja/git-tutorial/pull-request/07/
https://backlog.com/ja/git-tutorial/pull-request/08/

▼以下、慣れてから

10. コマンドでマージする

※その前にファストフォーワードしない設定
https://qiita.com/nog/items/c79469afbf3e632f10a1

git checkout <parent branchname>
git merge <child branchname>

11. コンフリクトの解消

12. その他便利機能

リモートの新着情報を取得

厳密には→ https://next.rikunabi.com/journal/20170120_t12_iq/

git fetch

ブランチの削除

git branch -d <branchname>

コミット前の変更点を戻す

一部ファイル
git checkout <filename>
全部
git checkout .

現在の作業を一時的に退避

git stash

git add してステージングしたものを戻す

git reset <filename>
git reset . (全ファイル)

既存のローカルファイルを、既存のリモートリポジトリと紐付ける

リモートに新規のリポジトリ作ったけど、既存ファイルがすでにあるから、
クローンから始めるんじゃなくて、既存ファイルを紐付けたいとき。

1.cd (チェンジディレクトリ)で該当のディレクトリに移動して、Gitを初期登録

git init

2.そのままリモートリポジトリを設定

git remote add origin <リモートのURL>
1
1
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
1
1