TortoiseGit ばかりを使用していたら、コマンドライン版 を忘れていたので、dotinstall等を参考にメモ
$ /usr/local/bin/git version git version 2.34.1
目次 - コマンド一覧
- 参考url
- git config - 個人設定と確認
- git init - repository の 初期化
- git add / git comit - file 追加と commit
- git remote add / git push - remote repository への file 追加と push(≒commit)
- git log - commit履歴の確認
- git status - commit未 有無の確認
- git diff - commit済との差分
- git mv / git rm - file移動と削除
- .gitignore - git管理に含めない
- git commit --amend - 直前のcommitを変更
- git reset --hard - 任意のversionに戻る
- git branch - ブランチ作成
- git init --bare / git push - 共有リポジトリ作成と、プッシュ
- git clone / git push - 共有リポジトリのクローン、プッシュ/プル
- github.com でのトークン取得
参考url
- git入門 (全22回) - プログラミングならドットインストール
- GitHub Pagesでウェブサイトを公開しよう (全11回) - プログラミングならドットインストール
- 【超入門】初心者のためのGitとGitHubの使い方 - RAKUS Developers Blog | ラクス エンジニアブログ
- サル先生のGit入門〜バージョン管理を使いこなそう〜【プロジェクト管理ツールBacklog】
git config - 個人設定と確認
$ git config --global user.name "$fullname" $ git config --global user.email "$emailto" $ git config --global color.ui true
$ git config -l user.name=$fullname user.email=$emailto color.ui=true
または
$ less ~/.gitconfig [user] name = $fullname email = $emailto [color] ui = true
git init - repository の 初期化
$ mkdir myweb $ cd myweb $ git init hint: Using 'master' as the name for the initial branch. This default branch name hint: is subject to change. To configure the initial branch name to use in all hint: of your new repositories, which will suppress this warning, call: hint: hint: git config --global init.defaultBranch <name> hint: hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and hint: 'development'. The just-created branch can be renamed via this command: hint: hint: git branch -m <name> Initialized empty Git repository in /home/end0tknr/tmp/myweb/.git/ # githubで新規リポジトリを作成する際、mainになってますが、 # localでは未だ master の為、上記のerrorが表示されます。 # そこで、以下のコマンドで main 化 $ git config --global init.defaultBranch main $ git init
git add / git comit - file 追加と commit
$ vi index.html $ git add . $ git commit
git remote add / git push - remote repository への file 追加と push(≒commit)
$ git remote add origin https://github.com/end0tknr/javaci.git
$ git push origin main Username for 'https://github.com': ないしょ@gmail.com Password for 'https://ないしょ@gmail.com@github.com': Enumerating objects: 14, done. Counting objects: 100% (14/14), done. Compressing objects: 100% (6/6), done. Writing objects: 100% (14/14), 1.76 KiB | 1.76 MiB/s, done. Total 14 (delta 0), reused 0 (delta 0), pack-reused 0 To https://github.com/end0tknr/javaci.git * [new branch] main -> main
「git push origin main」時に以下のようなエラーとなる場合、 「 https://github.com/settings/tokens 」でトークンを取得してください。
$ git push origin main Username for 'https://github.com': end0tknr Password for 'https://end0tknr@github.com': remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead. remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information. fatal: Authentication failed for 'https://github.com/end0tknr/javaci.git/'
git log - commit履歴の確認
$ git log
git status - commit未 有無の確認
$ git status
git diff - commit済との差分
$ git diff ## commit済と add未 の比較 $ git diff --cached ## commit済と add済 の〃
git mv / git rm - file移動と削除
$ git mv ~ $ git rm ~
.gitignore - git管理に含めない
$ vi .gitignore *.log
git commit --amend - 直前のcommitを変更
$ git add . $ git commit --amend
git reset --hard - 任意のversionに戻る
$ git reset --hard HEAD $ git reset --hard $COMMIT_ID $ git reset --hard ORIG_HEAD ## git resetをなかったことに
git branch - ブランチ作成
$ git branch ## ブランチ一覧表示 $ git branch $BRANCH_NAME ## 〃 作成 $ git branch -d $BRANCH_NAME ## 〃 削除 $ git checkouot $BRANCH_NAME ## 〃 へ 移動 $ git merge $BRANCH_NAME ## 〃 へ マージ
git init --bare / git push - 共有リポジトリ作成と、プッシュ
$ mkidr outweb.git $ cd outweb.git $ git init --bare $ cd ~/myweb $ git remote add origin ~/tmp/ourweb.git $ git config -l : remote.origin.url=/home/end0tknr/tmp/ourweb.git remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* X $ git push origin master $ git push origin main
git clone / git push - 共有リポジトリのクローン、プッシュ/プル
$ git clone ~/ourweb.git/ myweb2 $ git push origin main
$ cd ~/tmp/myweb $ git pull origin main
github.com でのトークン取得
2021/8/13以降、github は認証方式を変更しています。 「git push origin main」時に以下のようなエラーとなる場合、 以下の手順でトークンを発行し、これをパスワードとして利用して下さい。
https://github.com/settings/tokens へブラウザでアクセス
Generate new token ボタンをクリック
権限設定
様々なチェックボックスがありますが、 「git push origin main」程度であれば、「repo」のみでOK
Generate token ボタンをクリック