Many people get by for years in blissful ignorance of this concept. Don't feel bad if you're not familiar with worktrees in Git. To use this solution, you may need to learn about git add worktree. If you need git hooks, you will need to set them up for each new clone. Since they can't track each other, you must track where your clones live. (Shallow clones can help with this scenario, but they may not always be a good fit.) Additionally, your repository clones will be agnostic about each other. You don't need git stash or even WIP commits.Ĭons: Depending on the size of your repository, this can use a lot of disk space. Pros: You can work in multiple workspaces simultaneously. In this solution, rather than creating a new branch, you make a new clone of the repository for each new feature branch. If you do this accidentally, you should be able to restore your commit using git reflog, but it's less heartstopping to avoid this scenario entirely. When using this workflow, you never want to add a -hard to git reset. Also, WIP commits can sneak into your final product if you or your code reviewer are not vigilant. You don't have to work with the stash.Ĭons: You can have only one workspace at any time. Pros: This is an easy workflow for simple changes and also good for small repositories. git checkout -b feature-Y origin/master. ![]() git add -u (adds only modified and deleted files).When you're ready to switch back, rather than popping the stash, git reset HEAD~1 unrolls your WIP commit, and you're free to continue, much as you did in the earlier scenario but without touching the stash. Solution #2: WIP commit + branchĪ variation on this solution looks quite similar, but it uses a WIP (Work in Progress) commit rather than the stash. Also, depending on the state of your repository, working with the stash can be non-trivial. It can work quite well, especially for small repositories.Ĭons: When using this workflow, you can have only one workspace at a time. Pros: The nice thing about this approach is that this is a fairly easy workflow for simple changes. Probably the most common workflow to tackle this issue looks something like this: You will need to do this work in a new branch, feature-Y. You have just discovered you need to solve an unrelated problem. Imagine you are working in a branch called feature-X. ![]() Let's discuss the pros and cons of some common strategies for dealing with context switching using this example problem: Sometimes this adds very little overhead to your workflow, but other times, it can be a real pain. Anyone who spends a lot of time working with Git will eventually need to do some form of context switching.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |