Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
573 views
in Technique[技术] by (71.8m points)

branch - git working on two branches simultaneously

I have a project with many branches.

I would like to work on several branches simultaneously without switching back and forth with git checkout.

Is there any way I can do that besides copying the whole repository somewhere else?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Git 2.5+ (Q2 2015) supports this feature!

If you have a git repo cool-app, cd to root (cd cool-app), run git worktree add ../cool-app-feature-A feature/A. This checks out the branch feature/A in it's own new dedicated directory, cool-app-feature-A.

That replaces an older script contrib/workdir/git-new-workdir, with a more robust mechanism where those "linked" working trees are actually recorded in the main repo new $GIT_DIR/worktrees folder (so that work on any OS, including Windows).

Again, once you have cloned a repo (in a folder like /path/to/myrepo), you can add worktrees for different branches in different independent paths (/path/to/br1, /path/to/br2), while having those working trees linked to the main repo history (no need to use a --git-dir option anymore)

See more at "Multiple working directories with Git?".

And once you have created a worktree, you can move or remove it (with Git 2.17+, Q2 2018).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...