LoginSignup
1
0

Git Github コマンドメモ

Posted at

Git学習メモ

GitやGithubを利用する際のコマンドメモ

Git設定

  • Gitの設定をする
    • git config --global user.name "Takaaki Tsunoda"
    • git config --global core.editor "code --wait"
    • git config --global init.defaultBranch main
  • 設定の一覧を確認
    • git config --list
  • 設定を削除
    • git config --global --unset user.name
  • 設定例
      ~/Documents/Work ❯ git config --list
    credential.helper=osxkeychain
    user.email=takaaki.tsunoda@
    user.name=Takaaki Tsunoda
    core.hookspath=/usr/local/dd/global_hooks
    core.editor=code --wait
    init.defaultbranch=main
      ~/Documents/Work ❯

Gitコマンド

  • ローカルリポジトリを作成 *該当のディレクトリ上で作成
    • git init
  • ステータス確認git
    • git status
  • ステージング環境に登録
    • git add .
  • 差分確認 ワークツリーとステージングエリア
    • git diff
  • 差分確認 ステージングエリアとGitディレクトリ
    • git diff --cached
  • 認証付きでコミットを実行(GitHub)
    • git commit -S -m "update"
  • コミットを実行
    • git commit
  • コミットを実行(1行)
    • git commit -m "コマンドを追記"
  • ワークツリーの変更を取り消し、ステージングエリアの状態に戻す
    • git checkout -- README.md
  • ステージングエリアへの変更を元に戻す
    • git reset HEAD Git_MEMO.md
  • ファイルを削除 *要削除後のcommit
    • git rm remove_me.md
    • git commit -m "remove_me.mdファイルを削除"
  • ディレクトリを削除
    • git rm -r subDirectory
  • git管理外のファイルを指定
    • .gitignoreファイルを作成し、除外したいファイルやディレクトリを記載
  • コミット履歴の確認
    • git log
  • コミット履歴の確認 差分付き
    • git log -p

GitHub学習メモ

  • クローン *httpでクローンするとpushできないので注意
  • リモートリポジトリの設定確認
    • git remote -v
  • VSCodeのコマンドライン起動(カレントディレクトリがVS Codeで起動)
    • code .
  • ブランチを作成
    • git branch update-taka2noda-cli
  • 使用中ブランチ確認
    • git branch
  • ブランチに移動
    • git chechout update-taka2noda-cli
  • mainブランチとの差分確認
    • git diff main
  • main branchのlog確認
    • git log --oneline main
  • プルリク作成
    • git push origin main
  • GitHub上の変更をローカルリポジトリに取り込む
    • git pull origin main
  • ローカルに存在しないブランチを取り込む
    • git fetch origin
    • git checkout fix-branch
  • ローカルブランチの削除
    • git branch -d branch-name
  • Commit履歴の確認
    • git log
  • Commitの修正
    • git rebase -i <コミットハッシュ>
    • git commit --amend -S
  • ssh
    • git config --global user.signingkey ~/.ssh/id_rsa.pub
    • git config --global --list
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