1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Git】新しいブランチを作ってgit pushしたら、fatal: The current branch ブランチ名 has no upstream branch.と怒られた時の対処法

Last updated at Posted at 2021-03-10

症状

Gitで新しいbranchを作成しコード修正後にgit pushをしたら、「fatal: The current branch fix-heroku has no upstream branch.」と怒られてしまいました。
git checkout -b ブランチの名前

# 修正後
git add -A

git commit -m "コメント"

# pushしてエラー
git push
fatal: The current branch ブランチの名前 has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin fix-heroku

上記コマンドを日本語訳すると、

致命的:現在のブランチの分岐の名前には上流のブランチがありません
現在のブランチをプッシュしてリモートをアップストリームに設定するには、
git push --set-upstream origin fix-herokuをしてください

というものです。

解決方法

日本語訳する前に、commit→pushまでをやり直したら治りました。 上流ブランチが設定されていなかったためかと思われます。
# マスターブランチにチェックアウト
git checkout master

# マスターに作ったブランチをマージ
git merge ブランチ名

# githubにプッシュ
git push

Gitについては知識不足であるので、研鑽していきたいです。

参考

事象 : プッシュしたらfatal: The current branch ブランチ名 has no upstream branch. https://qiita.com/ponsuke0531/items/410735b544795506fdc5#%E4%BA%8B%E8%B1%A1--%E3%83%97%E3%83%83%E3%82%B7%E3%83%A5%E3%81%97%E3%81%9F%E3%82%89fatal-the-current-branch-%E3%83%96%E3%83%A9%E3%83%B3%E3%83%81%E5%90%8D-has-no-upstream-branch

git push --set-upstream origin masterって毎回聞かれるのをやめる
https://qiita.com/erii/items/e107b91a58f8250838da

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?