Aas*_*tha 1 git github git-bash
我正在学习使用 GitHub。
我想在我的本地存储库中的 git 中的不同分支上工作,该存储库具有从原始设置为上游的不同分支。
我是否必须为本地或我的计算机中的分支创建不同的文件夹以跟踪它们,或者我可以仅使用一个本地存储库查看不同分支的代码以及如何查看?
有几种方式
git checkout使用git checkout <branch>您“更改”文件夹的内容以反映所需分支中的文件。您的“根”文件夹每次都可以包含来自单个分支的内容
git worktree# Add "another" directory for a different branch
git worktree add <second path>/<branch name>
Run Code Online (Sandbox Code Playgroud)
这将在您的计算机上创建另一个文件夹,允许您同时在不同的分支上工作。
### Creating new worktree
# create new branch inside the worktree folder
git worktree -b <branch name> <path>
### Removing worktree
# Tell git to remove the workdir copy
git worktree delete ...
Run Code Online (Sandbox Code Playgroud)