0

I work in a large and multi-user git repository. To avoid large checkouts I use sparse checkout which works well for me.

  ----------------- master -----------------------------------
  |                    |                    |   
ProjectA          ProjectB              ProjectC 

Now I would like to create different branches, but I can't figure out the way of creating a branch which includes only one directory. Say I want to create a new branch which it will only includes ProjectA, can I do this?

1 Answer 1

2

Make branches in normal way (suppose remote name is origin).

Step 1

git checkout master
git checkout -b ProjectA
git push -u origin ProjectA

git checkout master
git checkout -b ProjectB
git push -u origin ProjectB

git checkout master
git checkout -b ProjectC
git push -u origin ProjectC

Step 2

git checkout ProjectA

delete all directory not belong to ProjectA

git add -A .
git commit -m"All source code of ProjectA"
git push -u origin ProjectA

Step 3

git checkout ProjectB

delete all directory not belong to ProjectB

git add -A .
git commit -m"All source code of ProjectB"
git push -u origin ProjectB

Step 4

git checkout ProjectC

delete all directory not belong to ProjectC

git add -A .
git commit -m"All source code of ProjectC"
git push -u origin ProjectC

(But your way isn't best practice.)

5
  • 1
    I can imagine what this answer would look like if OP included more directories in the question
    – Leon
    Commented Nov 21, 2016 at 15:57
  • For easy-to-understand.
    – Vy Do
    Commented Nov 21, 2016 at 16:01
  • @Leon this isn't a question tagged with bash, and doesn't need to go into that level of detail to communicate the premise of the solution.
    – Bryce Drew
    Commented Nov 21, 2016 at 16:15
  • Note that if, say, the changes in the ProjectA branch need to be merged back to master, it will have to be done with some care and/or manual intervention to avoid deleting more than is wanted in the master branch. The git subtree command can also help here.
    – wjl
    Commented Nov 21, 2016 at 16:16
  • 1
    @BryceDrew This answer could be simplified without using bash scripting - just show the steps of performing the suggested procedure for ProjectA, and add a sentence "repeat above procedure for ProjectB, ProjectC, etc".
    – Leon
    Commented Nov 21, 2016 at 16:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.