0
0
Gitdevops~15 mins

Creating a worktree in Git - Try It Yourself

Choose your learning style9 modes available
Creating a Git Worktree
📖 Scenario: You are working on a software project using Git. You want to work on a new feature without disturbing your current work. Using Git worktrees allows you to have multiple working directories linked to the same repository.
🎯 Goal: Learn how to create a new Git worktree for a new branch and switch to it safely.
📋 What You'll Learn
Create a new branch called feature-xyz
Create a new Git worktree in a folder called feature-xyz
Switch to the new branch in the new worktree
Verify the current branch in the new worktree
💡 Why This Matters
🌍 Real World
Developers often need to work on multiple features or fixes at the same time. Git worktrees let them do this without switching branches in the same folder, avoiding confusion and lost work.
💼 Career
Understanding Git worktrees is useful for software developers, DevOps engineers, and anyone managing code changes in teams. It helps maintain clean workflows and improves productivity.
Progress0 / 4 steps
1
Create a new branch called feature-xyz
Run the Git command to create a new branch named feature-xyz without switching to it.
Git
Need a hint?

Use git branch followed by the branch name to create a branch.

2
Create a new Git worktree in folder feature-xyz
Use the Git command to create a new worktree in a folder named feature-xyz and check out the branch feature-xyz there.
Git
Need a hint?

Use git worktree add <path> <branch> to create a new worktree.

3
Switch to the new worktree folder and check the current branch
Change directory to the new worktree folder feature-xyz and run the Git command to show the current branch.
Git
Need a hint?

Use cd feature-xyz to enter the folder and git branch --show-current to see the branch name.

4
Display the current branch name
Print the output of the command that shows the current branch name in the new worktree folder.
Git
Need a hint?

The output should be the branch name feature-xyz.