Git – separate folder for each branch. Setting it up

I have a need to keep 3 branches in 3 separate folders. (I know this is not a git way of doing things. But I need to do this for a reason).

Lets say the repo name is my_proj_repo.git
I have created a folder called prodv1 in my local system:

  • Sometimes git will track all remote git branches as local branches without me asking to. What happened?
  • Git: How to merge complex branches that have diverged a lot over the years
  • Find changeset id parent of a branch in tfs
  • Make another branch default?
  • Putting uncommitted changes at Master to a new branch by Git
  • How does git handle commits in a merge?
  • git clone url:/my_proj_repo.git

    Now I went into prodv1 folder and copied the files from a server, then:

    git commit -am "initial import"
    git push origin master

    That pushed the files to master.
    Now I created two more folders like the above in my local system


    I want to create two local and remote branches with the names:

    staging // this local branch points (push/pull) to staging remote branch
    dev     // this local branch points ((push/pull) to dev remote branch

    And these two branches should be in the corresponding folders:

    staging ==> stagingv1 folder
    dev     ==> devv1 folder

    I tried a few things and I guess I messed it up.
    Can someone point me commands/steps to get all this setup like I wanted?

    What I did was, went into the stagingv1 folder and did a git clone <repo>. But it defaults to master. And I am not sure how to initialize the staging branch here.

  • How to move a local git repository to the root folder and preserve history?
  • Git merge reports “Already up-to-date” though there is a difference
  • Correct Path for Git Remote Add from Amazon EC2 Instance to OSX Client Machine
  • Configuring so that pip install can work from github
  • Rake w/Git says 'fatal: Will not add file alias' but I can do it manually?
  • Bash - GIT small snippet for branch management
  • 2 Solutions collect form web for “Git – separate folder for each branch. Setting it up”

    I think that you might have to create all the branch in your repo

    $ git branch <name_of_your_new_branch>

    Then create all your folders and in each of your folder Clone the repo but Checkout the appropriate branches.

    Each folder should / may track only the appropriate branch

    Step 1 $ git branch [name_branch#1]
    Step 2 $ git branch [name_branch#2]
    Step 3 $ git branch [name_branch#3]

    Step 4 $ git push --all
    Step 5 md Folder #2
    Step 6 $ git clone [URL]
    Step 7 $ git checkout [name_branch]

    What you want to achieve has become simpler (or even trivial) since git 2.5 introduced the git worktree command.

    Basically, your your git repo has now completely free number of checked out branches, called work tree:

    • 0 (a bare repo)
    • 1 (a normal repo)
    • n > 1, a normal repo where you added n-1 work trees

    If your repo already contains your branch, you can do:
    git worktree add <path to branch> <branch name>
    Or, if that branch isn’t created yet and you want to branch off master:
    git worktree add -b <new branch name> <path to branch> master

    There you go. Note that you can’t checkout a branch in several repositories simultaneously.

    Git Baby is a git and github fan, let's start git clone.