LoginSignup
1
0

Gitコマンド一覧

Last updated at Posted at 2022-03-29

セットアップ

git init

・ディレクトリ下で使用する。

ユーザー名とメールアドレスを確認&再設定

$ git config user.name
$ git config user.email
$ git config --global user.name "Your Name"
$ git config --global user.email "your.mail.account@gmail.com"

・--globalオプションは、ユーザごとの設定を行う ~/.gitconfig ファイルに対して、サーバー全体に値を設定するという意味
・--localにすると、ディレクトリ下限定の設定となる。

ステージ、コミット、プッシュ

$ git add sample.php
$ git add -A
$ git commit -m "commit message"
$ git remote add origin https://github.com/user/repository.git
$ git push -u origin branchname

・pushは、ブランチごとに2回目以降は「git push」のみでOK

ブランチの編集

$ git checkout -b <branch>               # チェックアウトし、ブランチを新規作成
$ git branch --merged                    # マージ済みブランチの一覧
$ git branch -d                          # マージ済みブランチの削除
$ git branch -D <branch>                 # 強制的なブランチの削除
$ git fetch -p                           # リモートブランチの最新状態を取得(リモートブランチの削除も同期)
$ git for-each-ref refs/remotes --merged # マージ済みリモートブランチの一覧
$ git push --delete                      # リモートブランチの削除

プル

$ git pull origin master
$ git pull

アクセストークン設定

参考URL
https://qiita.com/shiro01/items/e886aa1e4beb404f9038

・アクセストークンとは?
→パスワードを暗号化したもの。passwordを聞かれたとき、普通に読める文字列の代わりに入力する。

Settings → Developer settings → Personal access tokens

参考URL

https://qiita.com/2m1tsu3/items/6d49374230afab251337
https://qiita.com/Toshimatu/items/f71a935612a55d6e674e

ローカルブランチの一括削除

例: develop, main のみ残したい場合

$ git checkout develop
$ git branch | grep -v 'develop\|main' | xargs git branch -d
1
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
1
0