Now that you have created a new worktree, switched to it and made your changes and pushed it. To go back to my main worktree directory I can just wt. Now to move to feature-x worktree directory, I can just use wt feature-x to cd into that directory to continue with the work. You can wt list which is equivalent to git worktree list to see the list of your worktrees. With this I can simply switch between my worktrees. To minimize this friction, I have built a small tool that let’s you switch between worktrees just with their partial or complete directory name.ĭownload wt CLI tool for faster switching between worktrees. You have to git worktree list and then copy the path navigate to the worktree of your choice. View the list of worktrees with git worktree listĪs much easy it is to create a worktree, it is equally difficult to navigate back and forth between them if they are spread across. Git worktree add command creates a worktree along with a branch that is named after the final word in your path.Įnter fullscreen mode Exit fullscreen mode You can create additional worktree on the same directory or move it to a desired path, I prefer the later. Let’s say the name of your feature is feature-x and you want the branch with the same name. create an replica of your project and switch to a new branch.Let’s say it’s a new feature, your workflow would look like this: OK back to our problem! Update changes? New Feature? Hot Fix? Whatever it is, you need to change to a different branch and work on it without any changes to your current work directory. In short, you can check out multiple branches at the same time by maintaining multiple clones of the same repository. Git worktree helps you manage multiple working trees attached to the same repository. Imagine this you are working on a feature where you have made bunch of changes to files that are not yet commited, and suddenly you need to work on a hot fix or a more priority feature. For example, if you wanted to create a new branch from the master. When branches are created using the -track option, they will be set up to linked to the remote branch. And finally, if you wanted to see them all: git branch -a master origin/HEAD origin/master. As developers, context switching is a part of the job that you need to account for in more than a few occasions. If you wanted to see remote branches: git branch -r origin/HEAD origin/master. Git has a solution to all of our problems, you just need to know where to look.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |