I just started using Git recently and I was reading up on Git best practices and it seems the most common one is to never work out of your master branch, always create a separate branch and work out of that. I'm wondering if this is only true when working with other developers or if this is something I should be doing if I'm the only developer on the project. If so, why? And how often should I merge the new branch? Why is that any different than just working out of the master branch and committing changes when necessary?
Thanks so much for your wisdom!
When you change a file in your work-tree, nothing happens to the copy in the index. It still matches the copy in the commit you chose. You have to run git add to copy the file from the work-tree, to the index.
In Git, branches are a part of your everyday development process. Git branches are effectively a pointer to a snapshot of your changes. When you want to add a new feature or fix a bug—no matter how big or how small—you spawn a new branch to encapsulate your changes.
Creating a new branch allows you to isolate your changes from the master branch. If your experimentation goes well you always have the option to merge your changes into the master branch. If things don't go so well you can always discard the branch or keep it within your local repository.
Originally Answered: If you do not commit and you switch branches (or pull), do you lose your tracked but uncommitted modified files (whether staged or not)? No. By default git checkout and git pull will refuse to perform an update that touches any files with uncommitted modifications (tracked or not).
Working out of a branch maybe a good idea if - for example - you are adding a phat new feature which wont be ready for a few weeks. Whilst you are working on your new feature, the Live app cocks up. What do you do if you havent branched (or tagged) from trunk (in this case the code branch supporting live) ? you have to revert all your work and maintain copies of your changes, ready to slap them back in when you have resolved your live issue, bad times...
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