Java Reference
In-Depth Information
Visit Multiple Realities
Being able to revert to a previous commit is great; it's like time travel. You
can always revisit your past. But why stop at just one past?
Git has a really neat feature called “branches.” These aren't like branches on
a tree, but more like branches in the space-time continuum: they are alternate
realities, or alternate timelines like in science-fiction stories.
Here's how you might use branches: Suppose you have everything working,
and maybe you've even released your plugin to the world. You want to
experiment with a new feature or two, but you need the current version of
your plugin around as well, in case there are any fixes you need to make for
your users. You need two different timelines: one where the plugin stays as
it is, maybe with a few fixes, and one where it's growing and gaining new
features. Maybe you want another timeline as well, where you try implementing
your features in a totally different way.
Not a problem!
You can create a new timeline easily using Git's branch command. branch by
itself will list all the current branches in your project:
$ git branch
* master
There's only one branch by default. It's named master , and you're in that
timeline. Now let's split the universe into two and make an alternate reality!
It's simple (don't type this in yet, we'll get to that in a second):
$ git branch cow-plane
And now you've created a new timeline. But you're not in it yet; you're still
in master . (Type gitbranch and you'll see the star is still next to master .) To switch
into the other timeline, type this:
$ git checkout cow-plane
Yes, it's our good friend gitcheckout again. Powerful magic. It's now transported
you to a different reality. Nothing you do here will affect the master timeline.
You can edit files, delete files, add new files, commit changes—everything.
And it's all in the cow-plane universe. You can go back to master at any time:
$ git checkout master
Search WWH ::

Custom Search