Git create new branch in new folder











up vote
0
down vote

favorite












I know how to create branches in git bash with



git branch develop



then to switch to that branch



git checkout develop



I want this specific branch to have it's own folder and anytime i commit to this branch the folder is updated.



How do i accomplish this in Git bash?










share|improve this question






















  • have separate repos ...
    – treyBake
    Nov 9 at 11:26






  • 3




    That's not really the idea of GIT. You have always checked out one branch and can commit to that. If you want to change branches, you have to checkout the new one.
    – Lennart Blom
    Nov 9 at 11:27















up vote
0
down vote

favorite












I know how to create branches in git bash with



git branch develop



then to switch to that branch



git checkout develop



I want this specific branch to have it's own folder and anytime i commit to this branch the folder is updated.



How do i accomplish this in Git bash?










share|improve this question






















  • have separate repos ...
    – treyBake
    Nov 9 at 11:26






  • 3




    That's not really the idea of GIT. You have always checked out one branch and can commit to that. If you want to change branches, you have to checkout the new one.
    – Lennart Blom
    Nov 9 at 11:27













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I know how to create branches in git bash with



git branch develop



then to switch to that branch



git checkout develop



I want this specific branch to have it's own folder and anytime i commit to this branch the folder is updated.



How do i accomplish this in Git bash?










share|improve this question













I know how to create branches in git bash with



git branch develop



then to switch to that branch



git checkout develop



I want this specific branch to have it's own folder and anytime i commit to this branch the folder is updated.



How do i accomplish this in Git bash?







git






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 11:23









user892134

1,10653578




1,10653578












  • have separate repos ...
    – treyBake
    Nov 9 at 11:26






  • 3




    That's not really the idea of GIT. You have always checked out one branch and can commit to that. If you want to change branches, you have to checkout the new one.
    – Lennart Blom
    Nov 9 at 11:27


















  • have separate repos ...
    – treyBake
    Nov 9 at 11:26






  • 3




    That's not really the idea of GIT. You have always checked out one branch and can commit to that. If you want to change branches, you have to checkout the new one.
    – Lennart Blom
    Nov 9 at 11:27
















have separate repos ...
– treyBake
Nov 9 at 11:26




have separate repos ...
– treyBake
Nov 9 at 11:26




3




3




That's not really the idea of GIT. You have always checked out one branch and can commit to that. If you want to change branches, you have to checkout the new one.
– Lennart Blom
Nov 9 at 11:27




That's not really the idea of GIT. You have always checked out one branch and can commit to that. If you want to change branches, you have to checkout the new one.
– Lennart Blom
Nov 9 at 11:27












1 Answer
1






active

oldest

votes

















up vote
4
down vote













The closest thing you can get is called "worktrees", you can read more about it here.



A short description of it is that you will have 1 main repository with a working folder, and you may for instance check out the master branch in this working folder.



Then additionally you would check out another branch, such as develop, into a separate working folder backed by the same repository.



This would allow you to have more than one branch "live" in a working folder on disk at the same time.



However, there is no "when I commit to this branch the folder is updated", instead you have to work in that folder.



It will basically look like two distinct clones, except that you don't have to push and pull between them since there is only one repository backing the two folders.



Here's a short example of how to set it up (using Windows command syntax):



C:> cd devprojects
C:devprojects> md MyAwesomeProject
C:devprojects> cd MyAwesomeProject
C:devprojectsMyAwesomeProject> git clone https://github.com/user/awesome.git master
.... snip

C:devprojectsMyAwesomeProject> cd master
C:devprojectsMyAwesomeProjectmaster> git worktree add ..develop develop
Preparing worktree (checking out 'develop')
HEAD is now at fca4b6c My most recent awesome commit

C:devprojectsMyAwesomeProjectmaster> cd ..
C:devprojectsMyAwesomeProject> dir

Volume in drive C is System
Volume Serial Number is 1234-5678

Directory of C:devprojectsMyAwesomeProject

02.10.2018 13.43 <DIR> .
02.10.2018 13.43 <DIR> ..
09.11.2018 10.26 <DIR> develop
08.11.2018 09.48 <DIR> master
0 File(s) 0 bytes
4 Dir(s) 229 636 960 256 bytes free


If you want to work in the develop branch, do it in the develop folder, and if you want to work on master, do it in that folder.



After you have committed in one folder you can switch to the other and merge the other branch in, because it is just 1 repository backing both worktrees.






share|improve this answer





















    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%2f53224808%2fgit-create-new-branch-in-new-folder%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
    4
    down vote













    The closest thing you can get is called "worktrees", you can read more about it here.



    A short description of it is that you will have 1 main repository with a working folder, and you may for instance check out the master branch in this working folder.



    Then additionally you would check out another branch, such as develop, into a separate working folder backed by the same repository.



    This would allow you to have more than one branch "live" in a working folder on disk at the same time.



    However, there is no "when I commit to this branch the folder is updated", instead you have to work in that folder.



    It will basically look like two distinct clones, except that you don't have to push and pull between them since there is only one repository backing the two folders.



    Here's a short example of how to set it up (using Windows command syntax):



    C:> cd devprojects
    C:devprojects> md MyAwesomeProject
    C:devprojects> cd MyAwesomeProject
    C:devprojectsMyAwesomeProject> git clone https://github.com/user/awesome.git master
    .... snip

    C:devprojectsMyAwesomeProject> cd master
    C:devprojectsMyAwesomeProjectmaster> git worktree add ..develop develop
    Preparing worktree (checking out 'develop')
    HEAD is now at fca4b6c My most recent awesome commit

    C:devprojectsMyAwesomeProjectmaster> cd ..
    C:devprojectsMyAwesomeProject> dir

    Volume in drive C is System
    Volume Serial Number is 1234-5678

    Directory of C:devprojectsMyAwesomeProject

    02.10.2018 13.43 <DIR> .
    02.10.2018 13.43 <DIR> ..
    09.11.2018 10.26 <DIR> develop
    08.11.2018 09.48 <DIR> master
    0 File(s) 0 bytes
    4 Dir(s) 229 636 960 256 bytes free


    If you want to work in the develop branch, do it in the develop folder, and if you want to work on master, do it in that folder.



    After you have committed in one folder you can switch to the other and merge the other branch in, because it is just 1 repository backing both worktrees.






    share|improve this answer

























      up vote
      4
      down vote













      The closest thing you can get is called "worktrees", you can read more about it here.



      A short description of it is that you will have 1 main repository with a working folder, and you may for instance check out the master branch in this working folder.



      Then additionally you would check out another branch, such as develop, into a separate working folder backed by the same repository.



      This would allow you to have more than one branch "live" in a working folder on disk at the same time.



      However, there is no "when I commit to this branch the folder is updated", instead you have to work in that folder.



      It will basically look like two distinct clones, except that you don't have to push and pull between them since there is only one repository backing the two folders.



      Here's a short example of how to set it up (using Windows command syntax):



      C:> cd devprojects
      C:devprojects> md MyAwesomeProject
      C:devprojects> cd MyAwesomeProject
      C:devprojectsMyAwesomeProject> git clone https://github.com/user/awesome.git master
      .... snip

      C:devprojectsMyAwesomeProject> cd master
      C:devprojectsMyAwesomeProjectmaster> git worktree add ..develop develop
      Preparing worktree (checking out 'develop')
      HEAD is now at fca4b6c My most recent awesome commit

      C:devprojectsMyAwesomeProjectmaster> cd ..
      C:devprojectsMyAwesomeProject> dir

      Volume in drive C is System
      Volume Serial Number is 1234-5678

      Directory of C:devprojectsMyAwesomeProject

      02.10.2018 13.43 <DIR> .
      02.10.2018 13.43 <DIR> ..
      09.11.2018 10.26 <DIR> develop
      08.11.2018 09.48 <DIR> master
      0 File(s) 0 bytes
      4 Dir(s) 229 636 960 256 bytes free


      If you want to work in the develop branch, do it in the develop folder, and if you want to work on master, do it in that folder.



      After you have committed in one folder you can switch to the other and merge the other branch in, because it is just 1 repository backing both worktrees.






      share|improve this answer























        up vote
        4
        down vote










        up vote
        4
        down vote









        The closest thing you can get is called "worktrees", you can read more about it here.



        A short description of it is that you will have 1 main repository with a working folder, and you may for instance check out the master branch in this working folder.



        Then additionally you would check out another branch, such as develop, into a separate working folder backed by the same repository.



        This would allow you to have more than one branch "live" in a working folder on disk at the same time.



        However, there is no "when I commit to this branch the folder is updated", instead you have to work in that folder.



        It will basically look like two distinct clones, except that you don't have to push and pull between them since there is only one repository backing the two folders.



        Here's a short example of how to set it up (using Windows command syntax):



        C:> cd devprojects
        C:devprojects> md MyAwesomeProject
        C:devprojects> cd MyAwesomeProject
        C:devprojectsMyAwesomeProject> git clone https://github.com/user/awesome.git master
        .... snip

        C:devprojectsMyAwesomeProject> cd master
        C:devprojectsMyAwesomeProjectmaster> git worktree add ..develop develop
        Preparing worktree (checking out 'develop')
        HEAD is now at fca4b6c My most recent awesome commit

        C:devprojectsMyAwesomeProjectmaster> cd ..
        C:devprojectsMyAwesomeProject> dir

        Volume in drive C is System
        Volume Serial Number is 1234-5678

        Directory of C:devprojectsMyAwesomeProject

        02.10.2018 13.43 <DIR> .
        02.10.2018 13.43 <DIR> ..
        09.11.2018 10.26 <DIR> develop
        08.11.2018 09.48 <DIR> master
        0 File(s) 0 bytes
        4 Dir(s) 229 636 960 256 bytes free


        If you want to work in the develop branch, do it in the develop folder, and if you want to work on master, do it in that folder.



        After you have committed in one folder you can switch to the other and merge the other branch in, because it is just 1 repository backing both worktrees.






        share|improve this answer












        The closest thing you can get is called "worktrees", you can read more about it here.



        A short description of it is that you will have 1 main repository with a working folder, and you may for instance check out the master branch in this working folder.



        Then additionally you would check out another branch, such as develop, into a separate working folder backed by the same repository.



        This would allow you to have more than one branch "live" in a working folder on disk at the same time.



        However, there is no "when I commit to this branch the folder is updated", instead you have to work in that folder.



        It will basically look like two distinct clones, except that you don't have to push and pull between them since there is only one repository backing the two folders.



        Here's a short example of how to set it up (using Windows command syntax):



        C:> cd devprojects
        C:devprojects> md MyAwesomeProject
        C:devprojects> cd MyAwesomeProject
        C:devprojectsMyAwesomeProject> git clone https://github.com/user/awesome.git master
        .... snip

        C:devprojectsMyAwesomeProject> cd master
        C:devprojectsMyAwesomeProjectmaster> git worktree add ..develop develop
        Preparing worktree (checking out 'develop')
        HEAD is now at fca4b6c My most recent awesome commit

        C:devprojectsMyAwesomeProjectmaster> cd ..
        C:devprojectsMyAwesomeProject> dir

        Volume in drive C is System
        Volume Serial Number is 1234-5678

        Directory of C:devprojectsMyAwesomeProject

        02.10.2018 13.43 <DIR> .
        02.10.2018 13.43 <DIR> ..
        09.11.2018 10.26 <DIR> develop
        08.11.2018 09.48 <DIR> master
        0 File(s) 0 bytes
        4 Dir(s) 229 636 960 256 bytes free


        If you want to work in the develop branch, do it in the develop folder, and if you want to work on master, do it in that folder.



        After you have committed in one folder you can switch to the other and merge the other branch in, because it is just 1 repository backing both worktrees.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 9 at 11:45









        Lasse Vågsæther Karlsen

        286k82519716




        286k82519716






























            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%2f53224808%2fgit-create-new-branch-in-new-folder%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







            這個網誌中的熱門文章

            Hercules Kyvelos

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud