Using Git branches

So I’m trying to improve my understanding of git, as I mentioned in my multiclipboard post in the Gallery. One of the features of git I haven’t really tried yet is branching. I understand the basic idea – it’s a way to, say, try something new without breaking everything else in a project.

Of course, all the exercises have “How to Break It” and “Extra Credit” sections. I feel like those would be prime opportunities to learn how to use branching.

I see it thus:

  • keep the original version of each exercise in master
  • do up the extra credit in an appropriate branch, like extra-credit

I know I could merge the changes from extra-credit into master, but would it be possible to explicitly keep them separate, like for “archival” purposes (to easily see how things changed)? Or is that not the way I should be going about branching?

I’m not the master of Git, but as I understand branches, it is a way to develop new features, refactor old one, etc. without messing around with the stable production branch. When you finished your work you can merge it into your master branch or every other branch (your develop branch for example). As always in git you can see your whole history, even if you merged a branch in another. I use branching a lot for my projects, so I can happily mess around with my code without fear. So as I see it you totally understand branching in Git :slight_smile:

Yes, you don’t have to merge the branches in if you don’t want to. Just leave it there, then checkout master to get back to your original code. If you do go to merge it, try out the github UI for doing merges. It’s pretty nice.

1 Like

Cool. Thanks, Zed. :slightly_smiling_face:

I found this article useful when starting out with git, and the paranoia of breaking my colleagues build (which I did a little to often)

https://www.codementor.io/git/tutorial/git-github-tutorial-for-beginners

1 Like
A free service run by Zed A. Shaw for learncodethehardway.org.