简体   繁体   中英

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

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?

There are several ways

git checkout

Using git checkout <branch> 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

在此处输入图片说明

# Add "another" directory for a different branch
git worktree add <second path>/<branch name>

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 <branch name> <path>

### Removing worktree

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

Listing worktree

在此处输入图片说明

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM