Git: autocomplete my prompt after failed push because missing -u flag












0














Using git, I often create local branches and then want to push them to the remote (e.g. Github). This requires the -u or --set-upstream flag.



Here is what git outputs without this flag:



$ git checkout -b newbranch
$ git push
fatal: The current branch cross_val has no upstream branch.
To push the current branch and set the remote as upstream, use

git push --set-upstream origin newbranch


Is there a way to have this suggestion copied to my prompt? So that I don't have to type it. Something like:



$ git checkout -b newbranch
$ git push
fatal: The current branch cross_val has no upstream branch.
To push the current branch and set the remote as upstream, use

git push --set-upstream origin newbranch

$ <tab>
$ git push --set-upstream origin newbranch









share|improve this question



























    0














    Using git, I often create local branches and then want to push them to the remote (e.g. Github). This requires the -u or --set-upstream flag.



    Here is what git outputs without this flag:



    $ git checkout -b newbranch
    $ git push
    fatal: The current branch cross_val has no upstream branch.
    To push the current branch and set the remote as upstream, use

    git push --set-upstream origin newbranch


    Is there a way to have this suggestion copied to my prompt? So that I don't have to type it. Something like:



    $ git checkout -b newbranch
    $ git push
    fatal: The current branch cross_val has no upstream branch.
    To push the current branch and set the remote as upstream, use

    git push --set-upstream origin newbranch

    $ <tab>
    $ git push --set-upstream origin newbranch









    share|improve this question

























      0












      0








      0







      Using git, I often create local branches and then want to push them to the remote (e.g. Github). This requires the -u or --set-upstream flag.



      Here is what git outputs without this flag:



      $ git checkout -b newbranch
      $ git push
      fatal: The current branch cross_val has no upstream branch.
      To push the current branch and set the remote as upstream, use

      git push --set-upstream origin newbranch


      Is there a way to have this suggestion copied to my prompt? So that I don't have to type it. Something like:



      $ git checkout -b newbranch
      $ git push
      fatal: The current branch cross_val has no upstream branch.
      To push the current branch and set the remote as upstream, use

      git push --set-upstream origin newbranch

      $ <tab>
      $ git push --set-upstream origin newbranch









      share|improve this question













      Using git, I often create local branches and then want to push them to the remote (e.g. Github). This requires the -u or --set-upstream flag.



      Here is what git outputs without this flag:



      $ git checkout -b newbranch
      $ git push
      fatal: The current branch cross_val has no upstream branch.
      To push the current branch and set the remote as upstream, use

      git push --set-upstream origin newbranch


      Is there a way to have this suggestion copied to my prompt? So that I don't have to type it. Something like:



      $ git checkout -b newbranch
      $ git push
      fatal: The current branch cross_val has no upstream branch.
      To push the current branch and set the remote as upstream, use

      git push --set-upstream origin newbranch

      $ <tab>
      $ git push --set-upstream origin newbranch






      bash git autocomplete






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 10 at 16:07









      Julien__

      1032




      1032






















          2 Answers
          2






          active

          oldest

          votes


















          1














          You could set up an alias that pushes the current branch to the remote.



          Configure the alias with the following command:



          git config --global alias.rpush '!git push --set-upstream origin $(git rev-parse --abbrev-ref HEAD)'


          The git rev-parse --abbrev-ref HEAD command returns the name of your current branch. Then run it with:



          git rpush


          You can choose to give the alias any other name according to your own preference.






          share|improve this answer





















          • Thanks Haxiel, this will do
            – Julien__
            2 days ago



















          0














          This won't do exactly what you want, but it will cut down the amount you need to type if you're using bash.



          https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash






          share|improve this answer





















          • I don't think this helps as the git completion scripts are already installed with git.
            – Julien__
            Dec 10 at 17:10












          • Guess it depends on the system. On my linux system it is a separate install and bashrc or profile needs to be updated to take advantage of it.
            – user103944
            Dec 11 at 18:34











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f487152%2fgit-autocomplete-my-prompt-after-failed-push-because-missing-u-flag%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You could set up an alias that pushes the current branch to the remote.



          Configure the alias with the following command:



          git config --global alias.rpush '!git push --set-upstream origin $(git rev-parse --abbrev-ref HEAD)'


          The git rev-parse --abbrev-ref HEAD command returns the name of your current branch. Then run it with:



          git rpush


          You can choose to give the alias any other name according to your own preference.






          share|improve this answer





















          • Thanks Haxiel, this will do
            – Julien__
            2 days ago
















          1














          You could set up an alias that pushes the current branch to the remote.



          Configure the alias with the following command:



          git config --global alias.rpush '!git push --set-upstream origin $(git rev-parse --abbrev-ref HEAD)'


          The git rev-parse --abbrev-ref HEAD command returns the name of your current branch. Then run it with:



          git rpush


          You can choose to give the alias any other name according to your own preference.






          share|improve this answer





















          • Thanks Haxiel, this will do
            – Julien__
            2 days ago














          1












          1








          1






          You could set up an alias that pushes the current branch to the remote.



          Configure the alias with the following command:



          git config --global alias.rpush '!git push --set-upstream origin $(git rev-parse --abbrev-ref HEAD)'


          The git rev-parse --abbrev-ref HEAD command returns the name of your current branch. Then run it with:



          git rpush


          You can choose to give the alias any other name according to your own preference.






          share|improve this answer












          You could set up an alias that pushes the current branch to the remote.



          Configure the alias with the following command:



          git config --global alias.rpush '!git push --set-upstream origin $(git rev-parse --abbrev-ref HEAD)'


          The git rev-parse --abbrev-ref HEAD command returns the name of your current branch. Then run it with:



          git rpush


          You can choose to give the alias any other name according to your own preference.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 10 at 17:23









          Haxiel

          994310




          994310












          • Thanks Haxiel, this will do
            – Julien__
            2 days ago


















          • Thanks Haxiel, this will do
            – Julien__
            2 days ago
















          Thanks Haxiel, this will do
          – Julien__
          2 days ago




          Thanks Haxiel, this will do
          – Julien__
          2 days ago













          0














          This won't do exactly what you want, but it will cut down the amount you need to type if you're using bash.



          https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash






          share|improve this answer





















          • I don't think this helps as the git completion scripts are already installed with git.
            – Julien__
            Dec 10 at 17:10












          • Guess it depends on the system. On my linux system it is a separate install and bashrc or profile needs to be updated to take advantage of it.
            – user103944
            Dec 11 at 18:34
















          0














          This won't do exactly what you want, but it will cut down the amount you need to type if you're using bash.



          https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash






          share|improve this answer





















          • I don't think this helps as the git completion scripts are already installed with git.
            – Julien__
            Dec 10 at 17:10












          • Guess it depends on the system. On my linux system it is a separate install and bashrc or profile needs to be updated to take advantage of it.
            – user103944
            Dec 11 at 18:34














          0












          0








          0






          This won't do exactly what you want, but it will cut down the amount you need to type if you're using bash.



          https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash






          share|improve this answer












          This won't do exactly what you want, but it will cut down the amount you need to type if you're using bash.



          https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 10 at 16:49









          user103944

          163




          163












          • I don't think this helps as the git completion scripts are already installed with git.
            – Julien__
            Dec 10 at 17:10












          • Guess it depends on the system. On my linux system it is a separate install and bashrc or profile needs to be updated to take advantage of it.
            – user103944
            Dec 11 at 18:34


















          • I don't think this helps as the git completion scripts are already installed with git.
            – Julien__
            Dec 10 at 17:10












          • Guess it depends on the system. On my linux system it is a separate install and bashrc or profile needs to be updated to take advantage of it.
            – user103944
            Dec 11 at 18:34
















          I don't think this helps as the git completion scripts are already installed with git.
          – Julien__
          Dec 10 at 17:10






          I don't think this helps as the git completion scripts are already installed with git.
          – Julien__
          Dec 10 at 17:10














          Guess it depends on the system. On my linux system it is a separate install and bashrc or profile needs to be updated to take advantage of it.
          – user103944
          Dec 11 at 18:34




          Guess it depends on the system. On my linux system it is a separate install and bashrc or profile needs to be updated to take advantage of it.
          – user103944
          Dec 11 at 18:34


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f487152%2fgit-autocomplete-my-prompt-after-failed-push-because-missing-u-flag%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Morgemoulin

          Scott Moir

          Souastre