LoginSignup
0
0

More than 5 years have passed since last update.

githubで先にローカルbranchを作ったときのエラー

Posted at

githubあまりいじってなくてつまずいた。
このあいだはgithubでリポジトリを作ってからcloneしてきてごにょごにょしてpushしたらうまくいったが、今回は先にローカルリポジトリを作ってしまった。

ローカル

  1. ソース書いた
  2. git init
  3. git add
  4. git commit

リモート(githubのサイト)

リポジトリを新規作成

再びローカル

  1. git remote add
  2. git push

ここで怒られた。

$ git push textfld
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream textfld master

提示されたヒントの通りやってみる。

$ git push --set-upstream textfld master
Username for 'https://github.com': negiboudu
Password for 'https://negiboudu@github.com': 
To https://github.com/negiboudu/textfld.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/negiboudu/textfld.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.

結局何をしたのか

githubでリポジトリを作った直後に出る画面。
あそこのサンプル通りのことをやっただけだった。。。

もろに同じようなお悩みが書いてあった。つまり自分が記事を書く必要などなかったのだ。
【メモ】GitHubでgit clone〜git pushまで

なんとなくこれが近いのかな〜と思った。
ローカルでgitを使用した後、gitHubに登録する方法

これ読めば解決しそう。と思ったけど結局やらなかった。
git push 時の error: failed to push some refs to

2013年の記事だけれど見てみた。けど結局自分の場合はやらなかった。
最新のgitだとgit pushした時に警告が出たのでその対策

気になったこと

  • 結局、githubのサイトでリポジトリを作る必要はどうしてもあるってことだよね・・・?全部ローカル側の操作で完結できないもんかと探っていた

  • git checkoutは、cloneとは違うんだろうけど(cloneはコピー作成と捉えた)、そうだとしたら、githubのサイトでリポジトリを作った後にcheckoutするのが自然?まぁやってみりゃいいんだな。

  • あと、originという名前を使う慣例を完全に無視してやっていた。でもあんまり気にしていない。どんどんぶっ壊していって覚えよう。

0
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
0
0