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

GitGit BASH

目次一覧

 状態:確認中  閲覧数:1,136  投稿日:2020-06-01  更新日:2020-06-01
最初に結論 / 失敗履歴 / 理解出来ない挙動

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

 閲覧数:375 投稿日:2020-06-01 更新日:2020-06-01

最初に結論


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'.



「ERROR: Repository not found. fatal: Could not read from remote repository.」と表示された場合は、

「$ git push -u」を実行すると、上流ブランチが設定される。→ これ以降「git push」「git pull」する際にレポジトリ、ブランチ引数を省略できる



類似度ページランキング
順位 ページタイトル抜粋
1 GitHub への PUSH へ 1回成功したぐらいでは、Git 理解したことには全然ならない 68
2 Git BASH 経由で、Windows10 から GitHub へ PUSH する 34
3 GitHubリモートリポジトリ名には日本語を使用できない。使用すると、ハイフンへ自動置換されてしまう 31
4 Twitter 複数アカウントでPOSTしたい 26
5 2022 年 10 月 28 時点における、私が理想とする(Web系プロジェクトバックアップ用途)gitコマンド実行履歴。※これまで一度もこの通りに実行できたことはない 24
6 TwitterOAuth では、画像URL を指定した画像投稿は出来ない(と思う)。ライブラリを使用しなければ出来るから、Twitter API の制限ではない(と思われる)  24
7 Git 失敗履歴2。「$ git reset」→ ソースコード削除。※Git BASH 経由で Windows10 から GitHub へ PUSH しようとするも、誤ってソースコードを削除してしまう 23
8 teratailでは質問しない 23
9 Twitter 回答を得られなかったQ 21
10 GitHub Desktop 試行錯誤履歴 21
11 トラブル発生する度に「Git GUI」を探すが、いつも「Git Bash」が一番じゃん、という結論になる。 20
12 2020年1月21日から最初に生成した以降、アクセストークンとアクセストークンシークレットは表示されなくなる 20
13 「Twitter Developers」でアプリケーションを新規作成するためには? SMS認証用コードを確認可能な電話番号の登録が必要 19
14 既存Twitterアカウントより電話番号を削除すると、どうなるの? 新規アプリ作成する際、再度電話番号を使用したSMS認証が必要になる 19
15 「Twitter API」経由でツイートを無料取得することはできません。 19
16 Twitter 回答を得られたQ 19
17 「Twitter Developer」審査結果に通り、appを作成。しかし、いつの間にか「User is not Authorized」が表示されていたケース 19
18 「Git Bash」→「GitHub」気づき 2022 19
19 Webサイトで課金決済するためにはどうすればよいか、調査 19
20 「Twitter API」は、2023 年 5 月 10 日時点では、SMS認証(電話番号登録)不要でプロジェクト作成できるよう仕様変更されています。 18
2024/4/27 6:58 更新
週間人気ページランキング / 4-20 → 4-26
順位 ページタイトル抜粋 アクセス数
1 GitHubリモートリポジトリ名には日本語を使用できない。使用すると、ハイフンへ自動置換されてしまう | GitHub(Git) 6
1 動画対応 | プログラミング 6
2 本 | ブックマーク 5
2 「Twitterデータ」対応 | Twitter Developer(Twitter) 5
3 Twitter API v1.1 | Twitter Developer(Twitter) 4
4 Windows10で使用できるGitクライアント | GitHub(Git) 3
5 開発 0 2
5 TwitterOAuth では、画像URL を指定した画像投稿は出来ない(と思う)。ライブラリを使用しなければ出来るから、Twitter API の制限ではない(と思われる)  | Twitter 2
6 Twitter アカウント管理 | Twitter Developer(Twitter) 1
6 同じ携帯電話番号でも、複数の「Twitter Developers」アカウントを作成可能 | Twitter Developer(Twitter) 1
6 0.GitHub リモートリポジトリ作成 / 1.「Git BASH」起動 / 2.ディレクトリ移動 1
6 個人事業主が導入可能な「支払、送金」機能を有する決済系サービス簡易比較表 1
6 過去の「0文字引用RT」を期間指定して取得しようとするも、挫折 | Twitter API (Twitter) 1
6 Twitter 旧レート制限 | Twitter API 旧仕様(Twitter) 1
6 感想履歴(技術エントリーを見返した際に不要だと感じた「当時の感想」をこのエントリーへ移動する) | Webサービス開発 1
6 Twitter 電話番号の問題 | Twitter Developer(Twitter) 1
6 2011年 1
2024/4/27 1:02 更新