LoginSignup
38
11

More than 1 year has passed since last update.

Git 現在のブランチを名前指定せずにpushする

Last updated at Posted at 2020-06-03

提起

$ git push
fatal: The current branch feature/issue-xxx has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin feature/issue-xxx

リモートリポジトリと関連付いてないローカルブランチをプッシュしようとするとこのメッセージが表示されます。

$ git push --set-upstream origin feature/issue-xxx

メッセージで言われる通りのコマンドを実行すればプッシュされますが、typoも怖いし毎度ブランチ名を指定するのは億劫ですね。

解決

$ git push -u origin HEAD

現在のブランチをリモートリポジトリに同じ名前でプッシュする便利な方法です。

  • -u--set-upstream の省略オプション
    • 2回目以降は git push でok

さらに楽する

push.defaultcurrent の値を設定します。

$ git config --global push.default current

$ git push

現在のブランチ名と同じ名前でリモートリポジトリへpushしてくれます。

参考

他に書いたGit関連の記事

38
11
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
38
11