'How can I create a git branch where I can work on one folder only?

I am developing modules for odoo, all these modules are in a main folder: modules_odoo. lets call these modules: module1, module2, module3.

I am using this main folder (modules_odoo) as my repository on github.

Lets say that I want to work on module2. I create a branch for this module: dev_module2. But in this branch automatically module1&3 are also present. What is a way to only work on one module whithout having the others in there as well.

As an other example: I have made a branch dev_modules, if I am working on module1 and module2 at the same time. And after a while, module1 is finished, but module2 isn't yet, how can I get module1 back to the main branch and keep module2 in the dev-branch?

Thanks in advance for the tips.



Solution 1:[1]

It seems as if this might be something to look at: https://unix.stackexchange.com/questions/233327/is-it-possible-to-clone-only-part-of-a-git-project

Personally I don't see much point in it unless the repository is huge. If you're concerned that you for some reason would commit changes in the wrong modules you can either run git status to check or just make sure you're running from the module's root directory if you're doing git add .

git add <module_name>/** from the root directory or similar should also work. This should also apply to the case where you only want to push changes from one specific module.

And after a while, module1 is finished, but module2 isn't yet, how can I get module1 back to the main branch and keep module2 in the dev-branch?

Commit only the changes to module1, then merge that commit to the main branch. Even if the module2 changes are committed, as long as it's a separate commit it will remain on the branch.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Zimon Kuhs