There are various scenarios I have encountered that require me to switch from one branch to another. Have you ever found yourself having to swap back and forth between different git branches, to work on two different features? Git makes this relatively easy to do, but it can still be a bit annoying and time consuming. Scenarios requiring frequent branch changes Finally I describe how git worktree allows you to check out multiple branches at once, so you can work on two branches simultaneously, without impacting each other. I then present some possible ways to avoid having to change branch. Otherwise you committed, and it's already there waiting for you.In this post I describe some scenarios in which you need to change git branches frequently and why this can sometimes be annoying. If you had stashed something, pop the stash: git stash pop. Remember as long as you don't push, you can commit willy nilly and clean it up later with interactive rebasing.Ĭheck out branch_a and continue working there. Once you're done experimenting, again either stash or commit. My favorite way is the all-in-one command git checkout -b branch_b. Now go back to master, and create branch_b. Stashes are a bit annoying to have hang around, and you can accidentally delete them or pop them when you don't mean to. Don't worry, you can clean it up later with an interactive rebase: git rebase -i. If you're going to be longer, just commit it. If you think you'll be back to branch_a within 15 minutes, perform a git stash save. You get an idea to try something different. git status has nice help text to help you along the way. Now you're free to go back to branch_b, git add stuff you want there, and commit that, too. Note that it only commits the items you added to the stage. Then perform a git commit to save what you want in branch_a. You need to git add all the items you want to for branch_a. In order to clean up your mess, perform a git status. To Clean It Up (assuming my conjecture is right) git will indeed let you carry over a dirty working directory. You checked out new branch branch_b, did some stuff, did not commit. I'm going to conjecture at what happened. Is this still possible?Īnd in terms of "the process", is there a better way to create and delete test branches? E.g. Since I didn't commit anything before, I can't figure out how to separate the changes pre- branch_b and post- branch-b. So the branch gets deleted but when I go back to branch_a to continue work from where I left off, I see the changes I made in branch_b are still there. Then, I deleted the branch thinking all the changes I made would get deleted too: git branch -d branch_b First I did a check-out of the original branch: git checkout branch_a I played around with this "test branch" and then decided to delete it. I went on to checkout a new branch ( branch_b). At this point, I have a few changes in branch A which I didn't stage or commit. I then decided to test a third party package knowing it may not work as I wanted. Basically, I started on a new branch ( branch_a) and then made a few changes. I'm a newbie to git, and got a little ahead of myself in creating/deleting branches and wanted to figure out the right process.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |