I have multiple active branches that I need to work on at the same time. Clearly I can create two working directories with a distinct branch per directory. Is that the only way to do it without having to "commit" and "checkout" in order to switch from one branch to another?
Build your strategy from these three concepts: Use feature branches for all new features and bug fixes. Merge feature branches into the main branch using pull requests. Keep a high quality, up-to-date main branch.
Git Flow. The Git Flow is the most known workflow on this list. It was created by Vincent Driessen in 2010 and it is based in two main branches with infinite lifetime: master — this branch contains production code.
If you are temporarily switching branches git stash
is useful, however, remember that commits don’t need to persist forever; you may make temporary commits to roll back later.
So my recommendation is, if it is a many hours long switch, to do a git commit
instead, because, depending on your memory, stashes can be easy to forget/lose/etc.
[In MyBranch] >$ git commit -m "WIP: Stuff I was working on." >$ git checkout AnotherBranch [Do Stuff] >$ git checkout MyBranch >$ git reset HEAD^ [Continue]
And since this is a question about best practices, remember to give your stash a useful message using git stash save
otherwise it can be difficult to find later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With