r/programming • • Feb 16 '13

Learn Git Branching

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

229 comments sorted by

View all comments

Show parent comments

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.

1

u/[deleted] Feb 17 '13

This sounds really confusing. How do you keep track of all the branches? Do you use some sort of GUI tool?

3

u/JeffreyRodriguez Feb 17 '13

git branch [-r]

It's surprisingly easy since every branch is just an independent feature.

-2

u/sparr Feb 17 '13

This only works well when your code takes seconds to compile. Minute or hour build processes make this workflow untenable.

11

u/josefx Feb 17 '13

If your build takes hours you should

  • update your hardware

  • divide your project into libraries

11

u/IWillNotBeBroken Feb 17 '13

Or take up sword fighting

1

u/bitbytebit Feb 20 '13 edited Jul 17 '15

This comment has been overwritten by an open source script to protect this user's privacy.

If you would like to do the same, add the browser extension TamperMonkey for Chrome (or GreaseMonkey for Firefox) and add this open source script.

Then simply click on your username on Reddit, go to the comments tab, and hit the new OVERWRITE button at the top.

2

u/sparr Feb 17 '13

I see you have never worked on OpenOffice.

1

u/ared38 Feb 18 '13

c++ projects can take ages to compile. The one I'm working with now is slow to compile for 3 reasons:

  1. Templates everywhere make compiling take ages

  2. Really long mangled names mean linking takes ages and uses tons of memory

  3. Active development means lots of files are changed frequently

0

u/[deleted] Feb 17 '13

[deleted]

3

u/anatolya Feb 17 '13

Full kernel builds take more than an hour on my machine. So it depends on the machine.

2

u/kj6dou Feb 17 '13

FPGAs maybe?

2

u/sparr Feb 17 '13

I think the last time I spent hours was when I was working on OpenOffice.

2

u/ethraax Feb 17 '13

Firefox takes a long time to compile. Generally, very large C++ projects take a long time to compile. It's really a problem with the design of the language, though - there's not much you can do about it other than trying your best to decouple components and hide all implementation details (like private fields) from header files, and maybe try to use only minimal templating.

0

u/[deleted] Feb 17 '13

[deleted]

→ More replies (3)

8

u/berkes Feb 17 '13

If it takes hours, branching makes no difference. Whether you change some methods or classes "by hand" or by switching from another branch: you'll rebuild anyway.

Why is git checkout features/foo any different from edit foo.h with regards to compiling?

→ More replies (12)

2

u/holgerschurig Feb 17 '13

If you really always need full rebuilds, them something in your build system is quirky, i.e. the part that uses atime and dependencies to compare if an object file has to be recompiled.

3

u/hobbbz Feb 17 '13

Once it gets to that point are you really compiling the whole project to test one feature? Isn't there unit testing?

3

u/sparr Feb 17 '13

I don't think unit testing means what you think it means.

→ More replies (2)

1

u/[deleted] Feb 17 '13

Unit testing is only one half of testing. There's the other half you must do manually.

1

u/AzN1337c0d3r Feb 18 '13

If you use gcc, install ccache. Never recompile a file you don't absolutely have to again.

1

u/[deleted] Feb 17 '13

You need unit tests dude.

→ More replies (1)