最初に結論 / 失敗履歴 / 理解出来ない挙動

カテゴリー: Git BASH  閲覧数:374 配信日:2020-06-01 10:31


最初に結論


GitHub への PUSH へ 1回成功したぐらいでは、Git 理解したことには全然ならない

「Git 理解した」と思うまでは
「PUSH」するためのディレククトリを別途作成して、そこで Git 操作する
※何かあった場合でも、元ソースコードからいつでも復活できるようにするため(バージョン管理ツールなのに本末転倒のような気もするが、仕方ない)

失敗履歴


「$ git reset」失敗履歴1。Git BASH 経由で Windows10 から GitHub へ PUSH しようとするも、誤ってソースコードを削除してしまう

理解出来ない挙動


たまたまうまくいっただけ
「理解できていないコマンド」を(バックアップ取得していない)コードに試すことは止めた方が良い

cd
作業ディレクトリ(Lドライブの「/3_開発/git/東京都/」)へ移動する
user@xxxx MINGW64 /c
$ cd /L/3_開発/git/東京都

git init
作業ディレクトリ内へ、Gitの(空の)ローカルリポジトリを作成する
user@xxxx MINGW64 /L/3_開発/git/東京都
$ git init
Initialized empty Git repository in L:/3_開発/git/東京都/.git/


git add -A
作業ディレクトリ内にあるファイルを全てコミット候補にする
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git add -A

git commit -m
インデックスに追加されたファイルをコミットする(コミットメッセージも指定する)
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git commit -m "first commit"
[master (root-commit) 99ac2bf] first commit
1 file changed, 1 insertion(+)
create mode 100644 "\346\235\261\344\272\254\351\203\275\346\270\257\345\214\272.txt"


git remote add origin
ローカルリポジトリに、リモートリポジトリを設定する
※リモートリポジトリは、GitHub の GUI 経由で事前作成しておく必要がある
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git remote add origin git@github.com:GitHubユーザー名/東京都.git

git remote -v
ローカルリポジトリに設定されている、リモートリポジトリ内容を一覧表示(URLも表示)
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git remote -v
origin  git@github.com:GitHubユーザー名/東京都.git (fetch)
origin  git@github.com:GitHubユーザー名/東京都.git (push)


git push origin master
ローカルリポジトリ(masterブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git push -u origin master
fatal: remote error:
  is not a valid repository name
 Email support@github.com for help


git remote add origin
ローカルリポジトリに、リモートリポジトリを設定する
※リモートリポジトリは、GitHub の GUI 経由で事前作成しておく必要がある
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git remote add origin git@github.com:GitHubユーザー名/test_2020_0601.git
fatal: remote origin already exists.


git push origin master
ローカルリポジトリ(masterブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git push -u origin master
fatal: remote error:
  is not a valid repository name
 Email support@github.com for help


git remote rm
ローカルリポジトリからリモート URL を削除する
※リモートリポジトリをサーバから削除するわけではない(ローカルリポジトリからリモートリポジトリへの参照を削除するだけ)
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git remote rm origin

git remote -v
ローカルリポジトリに設定されている、リモートリポジトリ内容を一覧表示(URLも表示)
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git remote -v

git remote add origin
ローカルリポジトリに、リモートリポジトリを設定する
※リモートリポジトリは、GitHub の GUI 経由で事前作成しておく必要がある
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git remote add origin git@github.com:GitHubユーザー名/test_2020_06_01.git

user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git push -u origin master
To github.com:GitHubユーザー名/test_2020_06_01.git
! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:GitHubユーザー名/test_2020_06_01.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


git remote add origin
ローカルリポジトリに、リモートリポジトリを設定する
※リモートリポジトリは、GitHub の GUI 経由で事前作成しておく必要がある
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git remote add origin git@github.com:GitHubユーザー名/test_2020_0601.git
fatal: remote origin already exists.


git push origin master
ローカルリポジトリ(masterブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git push -u origin master
To github.com:GitHubユーザー名/test_2020_06_01.git
! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:GitHubユーザー名/test_2020_06_01.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git remote -v
origin  git@github.com:GitHubユーザー名/test_2020_06_01.git (fetch)
origin  git@github.com:GitHubユーザー名/test_2020_06_01.git (push)


git remote rm
ローカルリポジトリからリモート URL を削除する
※リモートリポジトリをサーバから削除するわけではない(ローカルリポジトリからリモートリポジトリへの参照を削除するだけ)
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git remote rm origin

git remote -v
ローカルリポジトリに設定されている、リモートリポジトリ内容を一覧表示(URLも表示)
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git remote -v

git remote add origin
ローカルリポジトリに、リモートリポジトリを設定する
※リモートリポジトリは、GitHub の GUI 経由で事前作成しておく必要がある
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git remote add origin git@github.com:GitHubユーザー名/test_2020_0601.git

git push origin master
ローカルリポジトリ(masterブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git push -u origin master
To github.com:GitHubユーザー名/test_2020_0601.git
! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:GitHubユーザー名/test_2020_0601.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


git remote -v
ローカルリポジトリに設定されている、リモートリポジトリ内容を一覧表示(URLも表示)
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git remote -v
origin  git@github.com:GitHubユーザー名/test_2020_0601.git (fetch)
origin  git@github.com:GitHubユーザー名/test_2020_0601.git (push)


git push origin master
ローカルリポジトリ(masterブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git push -u origin master
To github.com:GitHubユーザー名/test_2020_0601.git
! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:GitHubユーザー名/test_2020_0601.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git fetch
warning: no common commits
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:GitHubユーザー名/test_2020_0601
* [new branch]      master     -> origin/master


git push origin master
ローカルリポジトリ(masterブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git push -u origin master
To github.com:GitHubユーザー名/test_2020_0601.git
! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:GitHubユーザー名/test_2020_0601.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git pull origin master
From github.com:GitHubユーザー名/test_2020_0601
* branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories


git push origin master
ローカルリポジトリ(masterブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git push -u origin master
To github.com:GitHubユーザー名/test_2020_0601.git
! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:GitHubユーザー名/test_2020_0601.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


git push origin master
ローカルリポジトリ(masterブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git push -u origin master
To github.com:GitHubユーザー名/test_2020_0601.git
! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:GitHubユーザー名/test_2020_0601.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git reset --soft HEAD^
fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'


user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git pull origin master
From github.com:GitHubユーザー名/test_2020_0601
* branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories


git push origin master
ローカルリポジトリ(masterブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git push -u origin master
To github.com:GitHubユーザー名/test_2020_0601.git
! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:GitHubユーザー名/test_2020_0601.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git pull --rebase origin master
From github.com:GitHubユーザー名/test_2020_0601
* branch            master     -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Applying: first commit


git push origin master
ローカルリポジトリ(masterブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる
user@xxxx MINGW64 /L/3_開発/git/東京都 (master)
$ git push -u origin master
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 311 bytes | 155.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:GitHubユーザー名/test_2020_0601.git
  1fec270..fc336b2  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.


週間人気ページランキング / 4-13 → 4-19
順位 ページタイトル抜粋 アクセス数
1 動画対応 | プログラミング 7
1 Twitter アカウント管理 | Twitter Developer(Twitter) 7
2 本 | ブックマーク 6
3 GitHubリモートリポジトリ名には日本語を使用できない。使用すると、ハイフンへ自動置換されてしまう | GitHub(Git) 5
4 気になるアプリ | ブックマーク 3
4 Windows10で使用できるGitクライアント | GitHub(Git) 3
5 同じ携帯電話番号でも、複数の「Twitter Developers」アカウントを作成可能 | Twitter Developer(Twitter) 2
5 RTだけ表示するやつ / 2020/3/20時点の結論 / Link 2
6 Git BASH(Git) カテゴリー 1
6 2012年 1
6 Git BASH 作業履歴 2022/10/20 / P48 site-rank(First-Ranking-Service) / 「Add a README」後「git push -f origin main」実行したため、「README」削除 | Git BASH(Git) 1
6 SFC(プログラミング) カテゴリー 1
6 「Twitter API」は、2023 年 5 月 10 日時点では、SMS認証(電話番号登録)不要でプロジェクト作成できるよう仕様変更されています。 | Twitter API (Twitter) 1
6 3.作業ディレクトリ内へ、Gitの(空の)ローカルリポジトリを作成する / 4.作業ディレクトリ内の変更をステージングエリアへ追加してコミット候補にする / 5.インデックスに追加されたファイルをコミットする(コミットメッセージも指定する) 1
6 6.ローカルリポジトリに、リモートリポジトリを設定する / ローカルリポジトリに設定されている、リモートリポジトリ内容を一覧表示(URLも表示) / ローカルリポジトリ(mainブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる 1
6 和田晃一良 年表 1
6 地雷API | API(プログラミング) 1
6 Amazonアソシエイト・プログラム 1
6 開発 0 1
6 「公式サポートページでユーザ同士が回答し合う体裁」を採用しているAPI / 制限事項の詳細を中途半端にしか公開していないAPI / 問い合わせ先が、別サービスの海外掲示板になっているAPI 1
2024/4/20 1:01 更新
指定期間人気ページランキング / 2020-5-27 → 2024-4-19
順位 ページタイトル抜粋 アクセス数
1 GitHubリモートリポジトリ名には日本語を使用できない。使用すると、ハイフンへ自動置換されてしまう | GitHub(開発環境) 883
2 fatal: remote error: is not a valid repository name | Git BASH(開発環境) 653
3 Twitter アカウント管理 | Twitter Developer(Twitter) 600
4 Twitter API | Twitter API (Twitter) 563
5 動画対応 | プログラミング 561
6 「Twitterデータ」対応 | Twitter Developer(Twitter) 502
7 開発 0 473
8 本 | ブックマーク 424
9 Webサービス | ブックマーク 414
10 マッチングサービス | Webサービスビジネス 401
11 Windows10で使用できるGitクライアント | GitHub(開発環境) 365
12 同じ携帯電話番号でも、複数の「Twitter Developers」アカウントを作成可能 | Twitter Developer(Twitter) 295
13 技術書籍 | プログラミング 294
14 気になった動画 | ブックマーク 286
15 埋め込みツイート | Twitter Developer(Twitter) 269
16 TwitterOAuth では、画像URL を指定した画像投稿は出来ない(と思う)。ライブラリを使用しなければ出来るから、Twitter API の制限ではない(と思われる)  | Twitter 266
17 個人事業主 | Webサービスビジネス 250
18 teratailでは質問しない | プログラミング 246
19 Twitter 電話番号の問題 | Twitter Developer(Twitter) 204
20 過去の「0文字引用RT」を期間指定して取得しようとするも、挫折 | Twitter API (Twitter) 178
2024/4/20 1:01 更新