i want to work on different branches in git in my local repository which have different branches from origin set as upstream

huangapple go评论68阅读模式
英文:

i want to work on different branches in git in my local repository which have different branches from origin set as upstream

问题

我正在学习如何使用GitHub。
我想在我的本地存储库中处理不同的Git分支,这些分支与上游设置的不同分支不同。
我是否必须在本地创建不同的文件夹来跟踪这些分支,或者我是否可以只使用一个本地存储库来查看不同分支的代码,如果可以,如何做到?

英文:

I am learning to use GitHub.
I want to work on different branches in git in my local repository which has different branches from origin set as upstream.

Do I have to create different folders for the branches in local or my computer to keep track of them or can I view codes of different branches using just one local repository and how?

答案1

得分: 8

有几种方法:

git checkout

使用 git checkout <branch> 可以将文件夹的内容更改为所需分支中的文件。每次您的“根”文件夹只能包含来自单个分支的内容。

git worktree

i want to work on different branches in git in my local repository which have different branches from origin set as upstream

# 为不同的分支添加“另一个”目录
git worktree add <second path>/<branch name>

这将在您的计算机上创建另一个文件夹,允许您同时在不同的分支上工作。

创建新的工作树

在工作树文件夹内创建新分支

git worktree -b <branch name> <path>

删除工作树

告诉 git 删除工作目录副本

git worktree delete ...

列出工作树

i want to work on different branches in git in my local repository which have different branches from origin set as upstream

i want to work on different branches in git in my local repository which have different branches from origin set as upstream

英文:

There are several ways

git checkout

Using git checkout &lt;branch&gt; you "change" the content of your folder to reflect the files in the desired branch. Your "root" folder can contain content from a single branch every time

git worktree

i want to work on different branches in git in my local repository which have different branches from origin set as upstream

# Add &quot;another&quot; directory for a different branch
git worktree add &lt;second path&gt;/&lt;branch name&gt;

This will create another folder on your computer which allows you to work on different branches simultaneously.

### Creating new worktree

# create new branch inside the worktree folder 
git worktree -b &lt;branch name&gt; &lt;path&gt;

### Removing worktree

# Tell git to remove the workdir copy
git worktree delete ...

Listing worktree

i want to work on different branches in git in my local repository which have different branches from origin set as upstream

i want to work on different branches in git in my local repository which have different branches from origin set as upstream

huangapple
  • 本文由 发表于 2020年1月3日 21:46:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/59579681.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定