English | 简体中文 |
Seamlessly switch between branches, keep your code organized, and run code across multiple directories—simplifying your workflow.
Managing multiple branches becomes tedious
Need to work on different versions simultaneously
Git worktree lets you effortlessly juggle multiple tasks across branches and commits without ever needing to leave your current workspace—ideal for managing complex projects. With git worktree, you can create extra working directories linked to different branches or commits. The benefit of this is that you can work on multiple tasks without switching branches, making it convenient for developers to handle different versions of the code. By creating a new working directory, we can switch between the current directory and the new one, each associated with different branches or commits. This allows you to perform Git operations such as committing, pulling updates, and more in each directory, independently of the others. In summary, git worktree offers a flexible way to manage multiple tasks or versions, boosting development efficiency.
Ctrl + Shift + R
to start.terminal.external.windowsExec
, with similar settings available on other platforms.
{
"terminal.external.osxExec": "iTerm.app",
"terminal.external.windowsExec": "C:\\Program Files\\Git\\bin\\bash.exe",
}
your-repo/.git/hook/post-merge
.
```sh
#!/bin/bash# Get the current directory path (Unix system) CURRENT_FOLDER=$(pwd) # Uncomment the following line to enable cygpath on Windows (Cygwin). # CURRENT_FOLDER=$(cygpath -w “$(pwd)”)
# Get the current Git branch name CURRENT_BRANCH_NAME=$(git rev-parse –abbrev-ref HEAD)
# Get the list of all worktrees and process each line. git worktree list –porcelain | grep “worktree” | while read -r LINE; do # Extract the worktree path. WORKTREE=$(echo “$LINE” | awk ‘{print $2}’)
# Uncomment the following line to enable cygpath on Windows (Cygwin).
# WORKTREE=$(cygpath -w "$WORKTREE")
# If the current directory path matches the worktree path, skip it.
if [ "$CURRENT_FOLDER" = "$WORKTREE" ]; then
continue
fi
# Get the branch name of the target worktree.
TARGET_BRANCH=$(git --work-tree="$WORKTREE" --git-dir="$WORKTREE/.git" rev-parse --abbrev-ref HEAD)
# If the target worktree's branch matches the current branch, process it.
if [ "$TARGET_BRANCH" = "$CURRENT_BRANCH_NAME" ]; then
echo "Processing worktree: $WORKTREE on branch: $TARGET_BRANCH"
git --work-tree="$WORKTREE" --git-dir="$WORKTREE/.git" reset --merge HEAD
fi done ``` - This post-merge script ensures consistency across multiple Git worktrees by resetting any matching branch to its merged state after a merge operation.
git switch --ignore-other-worktrees
.See the open issues for a full list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag “enhancement”. Don’t forget to give the project a star! Thanks again!
git checkout -b feature/AmazingFeature
)git commit -m 'Add some AmazingFeature'
)git push origin feature/AmazingFeature
)Distributed under the MIT License. See LICENSE for more information.
Jackiotyu - 2504448153@qq.com
Project Link: https://github.com/jackiotyu/git-worktree-manager