Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - Store branches in separate local directories

I'm rather new to git, and am trying to set up my repository the right way.

Basically my app is a platform of sorts, so implementations of this platform are based on the master branch, but have some small modifications to those files as well as some additional files.

I tried setting it up as branches, so I have a master branch, implementation_1 and implementation_2.

But as far as I can tell, that would mean that locally all the branches are stored in one directory, with their separation being only through git.

What I would like is to have 3 local directories, master,imp_1, and imp_2. If I make a change to one of the core files in the imp_1 directory, I want to be able to merge that change into the master branch and from there into imp_2.

I'm beginning to think these need to be 3 different repositories (the implementations being forks of the core). Is that the way to go? In that case, how would I go about handling the above scenario?

like image 305
kbanman Avatar asked Feb 24 '11 06:02

kbanman


2 Answers

Branches are first class citizens in Git. They are not "emulated" as branches like in older VCS such SVN, CVS, etc.

If you really need three different directories, because you want to have three distinct development environment, make 3 clones:

  • one in a directory called master
  • one in a directory called imp_1
  • one in a directory called imp_2

But to really understand branches, you can read "Pros and cons of different branching models in DVCS".


Or, since Git 2.5 (July 2015, 4 years after the OP's question), as I detailed in Multiple working directories with Git?, use git worktree.

That will be one clone, multiple folders (one per branch).
With Git 2.7+, you can then list those folders:

$ git worktree list /path/to/bare-source            (bare) /path/to/linked-worktree        abcd1234 [master] /path/to/other-linked-worktree  1234abc  (detached HEAD) 
like image 95
VonC Avatar answered Oct 09 '22 04:10

VonC


you can create three clones of your repository and merge between those. forks in git are no different from branches the way they are merged and such. you can easily do:

git merge ../master
git pull ../imp_2

when cloning locally git will hardlink your objects and even save disk space

like image 31
knittl Avatar answered Oct 09 '22 04:10

knittl