There are a number of features Git has had for some time that go
largely unnoticed by most people. Being able to refer to branches
using the @{-1} notation (and its - alias) is one of the features
I use on a regular basis that most people seem unaware of, even though
they’ve been around since version 1.6.2.
Being able to refer to the previously checked out branch using a
consistent notation is particularly handy if you tend to keep around a
number of topic branches with similar enough names to make tab
completion a bit of a hassle. When working on the Puppet codebase,
for example, I will often have a number of branches of the form
${ticket}/${integration_branch}/${ticket_number}-${description}.
Tab completing one of these can be annoying at times (especially with
multiple tickets that are close together numerically and are intended
for the same integration branch). Where @{-1} comes in handy is
when I go to merge the topic branch into the integration branch to
make sure it merges cleanly, and all the tests still pass.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
After running the tests, getting back to the topic branch for any
further work is quite simple, using the - alias for @{-1}. For
people used to using cd -, switching branches like this will
probably come quite naturally.
1 2 | |
In addition to referring to the previously checked out branch @{-N}
will refer to the Nth previously checked out branch (@{-2}, etc).