Putting recent committed work on a branch in Git











up vote
0
down vote

favorite












I've been doing some work on the master branch. I've made several commits, but my commits aren't pushed yet. I've decided that the work is extensive enough that I should put it on a branch. (This sounds like Create branch from current working tree and reset to HEAD but in that question no commits had been made, so the questions are not identical.)



I'm an experienced Git user and I'm reasonably confident in theory that I can simply do the following:



git branch new-branch
git reset commit-before-start-of-work --hard


So if I wanted to put all the work I did after my last push on a branch, I would do:



git branch new-branch
git reset origin/master --hard


This seems logical and easy, but since I haven't done this or even thought of it until today, I wanted to ask before trying it out. Since I didn't find an identical question, perhaps it will be helpful to someone as well.










share|improve this question




























    up vote
    0
    down vote

    favorite












    I've been doing some work on the master branch. I've made several commits, but my commits aren't pushed yet. I've decided that the work is extensive enough that I should put it on a branch. (This sounds like Create branch from current working tree and reset to HEAD but in that question no commits had been made, so the questions are not identical.)



    I'm an experienced Git user and I'm reasonably confident in theory that I can simply do the following:



    git branch new-branch
    git reset commit-before-start-of-work --hard


    So if I wanted to put all the work I did after my last push on a branch, I would do:



    git branch new-branch
    git reset origin/master --hard


    This seems logical and easy, but since I haven't done this or even thought of it until today, I wanted to ask before trying it out. Since I didn't find an identical question, perhaps it will be helpful to someone as well.










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I've been doing some work on the master branch. I've made several commits, but my commits aren't pushed yet. I've decided that the work is extensive enough that I should put it on a branch. (This sounds like Create branch from current working tree and reset to HEAD but in that question no commits had been made, so the questions are not identical.)



      I'm an experienced Git user and I'm reasonably confident in theory that I can simply do the following:



      git branch new-branch
      git reset commit-before-start-of-work --hard


      So if I wanted to put all the work I did after my last push on a branch, I would do:



      git branch new-branch
      git reset origin/master --hard


      This seems logical and easy, but since I haven't done this or even thought of it until today, I wanted to ask before trying it out. Since I didn't find an identical question, perhaps it will be helpful to someone as well.










      share|improve this question















      I've been doing some work on the master branch. I've made several commits, but my commits aren't pushed yet. I've decided that the work is extensive enough that I should put it on a branch. (This sounds like Create branch from current working tree and reset to HEAD but in that question no commits had been made, so the questions are not identical.)



      I'm an experienced Git user and I'm reasonably confident in theory that I can simply do the following:



      git branch new-branch
      git reset commit-before-start-of-work --hard


      So if I wanted to put all the work I did after my last push on a branch, I would do:



      git branch new-branch
      git reset origin/master --hard


      This seems logical and easy, but since I haven't done this or even thought of it until today, I wanted to ask before trying it out. Since I didn't find an identical question, perhaps it will be helpful to someone as well.







      git git-branch






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 19:01

























      asked Nov 7 at 17:31









      Garret Wilson

      5,6711170153




      5,6711170153
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          Yes, that's correct. Before starting, make sure that git status shows everything committed, since git reset --hard will replace the current index and work-tree contents without questioning you, even if they have not been committed anywhere.






          share|improve this answer





















          • Thanks for the confirmation. I removed the -b designation, which I had mistakenly included from the git checkout -b new-branch form, which creates and switches to a new branch. I just now tried everything, and it works like a charm.
            – Garret Wilson
            Nov 11 at 19:02











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          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',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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%2fstackoverflow.com%2fquestions%2f53194760%2fputting-recent-committed-work-on-a-branch-in-git%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          Yes, that's correct. Before starting, make sure that git status shows everything committed, since git reset --hard will replace the current index and work-tree contents without questioning you, even if they have not been committed anywhere.






          share|improve this answer





















          • Thanks for the confirmation. I removed the -b designation, which I had mistakenly included from the git checkout -b new-branch form, which creates and switches to a new branch. I just now tried everything, and it works like a charm.
            – Garret Wilson
            Nov 11 at 19:02















          up vote
          0
          down vote



          accepted










          Yes, that's correct. Before starting, make sure that git status shows everything committed, since git reset --hard will replace the current index and work-tree contents without questioning you, even if they have not been committed anywhere.






          share|improve this answer





















          • Thanks for the confirmation. I removed the -b designation, which I had mistakenly included from the git checkout -b new-branch form, which creates and switches to a new branch. I just now tried everything, and it works like a charm.
            – Garret Wilson
            Nov 11 at 19:02













          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          Yes, that's correct. Before starting, make sure that git status shows everything committed, since git reset --hard will replace the current index and work-tree contents without questioning you, even if they have not been committed anywhere.






          share|improve this answer












          Yes, that's correct. Before starting, make sure that git status shows everything committed, since git reset --hard will replace the current index and work-tree contents without questioning you, even if they have not been committed anywhere.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 7 at 17:40









          torek

          181k17231313




          181k17231313












          • Thanks for the confirmation. I removed the -b designation, which I had mistakenly included from the git checkout -b new-branch form, which creates and switches to a new branch. I just now tried everything, and it works like a charm.
            – Garret Wilson
            Nov 11 at 19:02


















          • Thanks for the confirmation. I removed the -b designation, which I had mistakenly included from the git checkout -b new-branch form, which creates and switches to a new branch. I just now tried everything, and it works like a charm.
            – Garret Wilson
            Nov 11 at 19:02
















          Thanks for the confirmation. I removed the -b designation, which I had mistakenly included from the git checkout -b new-branch form, which creates and switches to a new branch. I just now tried everything, and it works like a charm.
          – Garret Wilson
          Nov 11 at 19:02




          Thanks for the confirmation. I removed the -b designation, which I had mistakenly included from the git checkout -b new-branch form, which creates and switches to a new branch. I just now tried everything, and it works like a charm.
          – Garret Wilson
          Nov 11 at 19:02


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • 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%2fstackoverflow.com%2fquestions%2f53194760%2fputting-recent-committed-work-on-a-branch-in-git%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

          Florida Star v. B. J. F.

          Error while running script in elastic search , gateway timeout

          Adding quotations to stringified JSON object values