Git add a branch to one directory?

I have a git repository on GitHub, with three different folders and only with the main branch. How can I create a new branch in one directory instead of three?

+6
source share
4 answers

You can not. Git works throughout the repository, not in separate directories. You can:

  • Create a new branch, and on this branch only change the settings in the destination directory.
  • You can obviously follow the william.eyidi suggestion and delete other directories, but this will be difficult if you want to merge the changes back into your main branch.
  • You can configure a specific directory as a submodule of Git with its own history, separate from the parent repository, but this is probably more complicated than it costs.
+8
source

I think you should delete this repository and do it again, but this time with the right branch.

You mentioned that you have 3 folders, but you want to use only one folder. So go to your folder with git.

This is an example in Git - Bash

cd /path/to/your/folder git init git add --all git commit -m "My first commit." git push origin master 

The origin should be the address of github-repository.

+1
source
  • git checkout -b
  • delete local directories 2 others.
  • git click
0
source

After creating a new branch, instead of checking the branch for the entire repository, you can add a directory that tracks this branch, while other directories track another branch.

 git worktree add masterBranchDirectory master 

The masterBranchDirectory directory is now a copy of the entire repository. After you go to this directory, you will automatically go to the main branch.

0
source

Source: https://habr.com/ru/post/986576/


All Articles