2
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コマンド一覧

以下、Gitコマンドの一覧です。

基本的なGitコマンド

  • 新しいGitリポジトリを作成します。

    git init
    
  • 既存のリポジトリをクローン(コピー)します。

    git clone <クローンしたいリポジトリのURL>
    
    #例:
    git clone https://github.com/user/repo.git
    
  • 作業ディレクトリの状態を表示します。変更されたファイルやコミットされていないファイルを確認できます。

    git status
    
  • 変更されたファイルをステージングエリアに追加します。

    git add <ステージングしたい変更を指定>
    
    #例: すべての変更を追加
    git add . 
    #例: sample_dirの変更を追加
    git add sample_dir 
    
  • ステージングエリアの変更をリポジトリにコミット(保存)します。

    git commit -m "コミットメッセージ"
    
  • ローカルリポジトリのコミットをリモートリポジトリにプッシュします。

    git push <リモートリポジトリ名> <ブランチ名>
    
    #例: 
    git push origin main
    
    #以下とすることで、プッシュと同時に、以降ローカルブランチとリモートブランチが連携されるように設定できる
    git push --set-upstream <リモートリポジトリ名> <ブランチ名>
    
  • リモートリポジトリから変更をプルして、ローカルリポジトリにマージしま*す。

    git pull <リモートリポジトリ名> <ブランチ名>
    
    #例: 
    git pull origin main
    

特別なGitコマンド

  • 新しいブランチを作成したり、現在のブランチを表示します。

    #現在のブランチを表示
    git branch
    
    #新しいブランチを作成
    git branch new-branch
    
  • ブランチを切り替えたり、特定のコミットに移動します。

    #ブランチを切り替え
    git checkout new-
    
    # 特定のコミットに移動
    git checkout <commit-hash>
    
  • 他のブランチを現在のブランチにマージします。

    git merge <他のブランチ>
    
    #例
    git merge new-branch
    
  • 一つのブランチの変更を別のブランチの先頭に移動します。よりクリーンな履歴を保つために使用されます。

    git rebase <変更元ブランチ>
    
    #例: mainブランチの変更を現在のブランチに適用し、履歴を整理します。
    git rebase main 
    

その他便利なコマンド

  • リポジトリのコミット履歴を表示します。

    git log
    
  • 変更点を表示します。

    git diff
    
  • 作業中の変更を一時的に保存し、クリーンな作業ディレクトリに戻します。

    git stash
    
  • 一時的に保存した変更を再度適用します。

    git stash pop
    

まとめ

これらのコマンドを使いこなすことで、Gitの基本的な操作を理解し、効率的にバージョン管理ができるようになります。
チートシート的な用途で使っていだけると!

2
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
2
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?