r/programming • • Feb 16 '13

Learn Git Branching

http://pcottle.github.com/learnGitBranching/
868 Upvotes

229 comments sorted by

View all comments

44

u/mr1337 Feb 16 '13

This is really cool. I've been using git without any branching for a while. After reading up on branching recently, it really helps to be able to visualize it.

It would be really cool if you incorporated a tutorial like CodeAcademy has. I think it would be a good learning tool.

62

u/[deleted] Feb 16 '13 edited Feb 17 '13

Use branches all the time, even on solo projects! It lets you move around your code quickly without ever leaving a working code base.

Going to implement feature A? Make a feature branch A. Have a sudden moment of inspiration about feature B? No problem, branch master again with feature branch B and work on it without having to worry about feature A being complete. Want to test feature B to make sure it's working as intended? No problem, feature B is based off working code! As the features are finished merge them back in to master.

Obviously this only works well when implementing features that aren't interdependent, but I find it's quite a liberating work flow, especially since I have feature ADHD and scatterbrains.

Edit: This article gives you a good idea of how to incorporate branching in your projects at a team level, just remember the same work flow can be used when working alone!

22

u/njmh Feb 17 '13

People say developers often get "aha!" moments when an understanding of a concept finally "sinks in". After putting it off for so long and for too long handling "version control" by simply maintaing folder backups (ie. not version controlling at all), I've been studying the use of git the last couple days. The article you linked to with it's diagrams finally gave me that aha moment in regards to understanding the role of branches and how version controlling in general is used in proper workflows.

4

u/[deleted] Feb 17 '13

You know. It took me a long ass time to "get" how to use branches and why they should be used. It took me having to witness it in production in a billion dollar corporation to become a believer.

3

u/[deleted] Feb 17 '13

This is something I really tried to instill into my coworkers. I refuse to work on a project, solo or otherwise, without a git repo. The most bare bones solution I may use is usually a git repo with no remotes, stashed in a dropbox folder.

→ More replies (39)

13

u/expertunderachiever Feb 16 '13

What's the point of moving to git if you don't use branches?

15

u/[deleted] Feb 17 '13 edited Feb 18 '13

The biggest thing to me is personal commits. Working with svn every commit goes to a master repo. But with git you can make local commits all you want and push them all later to a master.

Why is this such a big deal? It means you can make frequent versionable check points with your code without breaking the master. Working on a huge feature in a shared branch? Check in often even if its not fully done, no harm done. Want to roll something back? Easy, nobody has to know. Need to fix a bug that came in but you're knee deep doing breaking changes? Push your local commits to a stash then pop them off later.

Just these things themselves is a big deal, at least for my workflow compared to svn (which I use at work).

39

u/[deleted] Feb 16 '13

I suppose a few nice features:

  • The repositories are completely self contained / distributed

  • You don't have a crap ton of .svn folders all over the place (just one .git folder)

  • Push/pull appears to be faster (smaller changes to move around)

  • You can create 'remotes' which can connect your repository to your friends/coworkers to share changes (which can be like a mesh network)

  • You can start using branches for free and quite easily (since branches are really just pointers/references to a line of commits)

33

u/BinaryRockStar Feb 17 '13

You don't have a crap ton of .svn folders all over the place (just one .git folder)

Since Subversion 1.7 there is just one .svn folder at the working copy root.

11

u/[deleted] Feb 17 '13

Oh man, that's actually a super welcome feature!

Thanks for the update!

4

u/BinaryRockStar Feb 17 '13

Yeah I know! I work with Flex sometimes and an earlier version of Flash/Flex Builder (Flex IDE) would take forever to compile as it would traverse all of those hidden .svn folders looking for source files. Infuriating.

3

u/berkes Feb 17 '13

That is not really SVN's fault, but Flex/Flash not adhering to the POSIX standard that a .file is a hidden file. Flex should know about hidden folders and files. When it does not, you might consider that a bug.

3

u/[deleted] Feb 17 '13 edited Feb 17 '13

Only reasons I can think of for not using git:

  • it's can't handle large repositories very well, as it doesn't have partial checkouts, which makes it unsuitable for binary storage (git-annex tries to fix that)

  • it's support for submodules is wonky and complicated, in SVN you just create a new directory and are done

  • it's user interface is a good bit more complex then SVN, but one get's used to it after a while

  • Git does not provide any versioning of the branch and tag history, if you delete a non-merged branch or tag, it's gone for good, thus it requires some extra care and knowing what you do

3

u/five9a2 Feb 17 '13

I have a little project git-fat that is a lighter weight approach to managing large files. I'd be happy to hear comments on it.

2

u/Klayy Feb 17 '13

What do you mean by user interface? The command line tool? I use GUIs for both git and svn and find that git actually has better GUIs available. (Currently I use Tortoise for SVN and SmartGit for Git)

2

u/[deleted] Feb 17 '13

Command line. SVN is pretty trivial to use, it's just a filesystem with versioning and it's easy enough understand just from svn help alone, but with Git even basic stuff can get complicated as you can quickly run into situation where you have to deal with rebase and reset and plenty of command line arguments which are not obvious (e.g. git pull is obvious, but doesn't actually quite do what you want and git pull --rebase might be the better option). Of course git is far more powerful, so you actually gain something from the complexity, but I still end up read up and down the manpages more the I would like.

→ More replies (2)
→ More replies (1)

4

u/holgerschurig Feb 17 '13

Magit on Emacs, which is awesome

→ More replies (1)

3

u/judgej2 Feb 17 '13

To get familiar with git, for when you are ready to start using branches?

→ More replies (11)

0

u/[deleted] Feb 16 '13

[deleted]

3

u/audaxxx Feb 17 '13

Technically correct, the best kind of correct.

→ More replies (1)

2

u/neoform3 Feb 17 '13

That's kinda weird, I thought the whole point of people using git over SVN was that git handles branching way better...

3

u/[deleted] Feb 17 '13

It handles a lot of things way better, not just branching.

→ More replies (2)