I have recently created a repository. I made two branches in it, master
and dev
. Now when I copy files in the repositry's directory then the files are added to both the branches. But I only want to add files to dev
branch and then after the work is done in dev
then I will copy contents from dev
's folder into master's
folder. Unfortuanately both the branches are thought of as the same folder by git.
So how to have different branches in different folders in git?
You can prefix the branch you want to create with the folder name or branch type you want. For example you can put a feature branch into a feature folder by making the branch name. This is an example of how the tree will look.
You may like git-worktree. This allows you to checkout different branches to different directories.
E.g.
git checkout master
git worktree add ../dev dev
Judging from your comment
Suppose in a project there are two branches
frontend
andbackend
. Frontend branch contains only static html pages and backend branch contains dynamic php pages. I download frontend branch then as you say it will also contain backend's php files too.
you have grossly misunderstood the purpose of branches.
You do not use branches to separate your files depending on their purpose. For this, you usually place them in different directories.
You use branches to separate a project state from a different project state that needed some changes. Take a website that you have completed. It has a set of files for the frontend and the backend. You have both sets in a branch master
, and it is working well and stable. Now you decide to make the theme customizable. This typically needs changes in both sets of files. But you do not want to extinguish the current state of your website. Hence you make a new branch devel
and make the changes (on both sets of files) on the new branch. Now, by checking out master
and devel
, you can switch back and forth between the stable state of the website and the development state.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With