GIT: interact between two branches

Wow, this is one of the best things I’ve discovered in recent history. Not the best, that’s something completely different, but certainly one of the best related to work. It’s a shorthand that has already saved me countless clicks and keystrokes.

Let me set up a scenario (#1):

  1. Set up a git repository somewhere (local, GitHub, Bitbucket, Beanstalk, etc)
  2. Switch away from develop and master to work on a feature
  3. Test
  4. Commit to the feature branch
  5. Switch to develop and merge feature branch to test again on the staging environment. Alternatively have someone do your pull request to merge instead of doing this yourself.
  6. Either switch back to the feature branch to continue working on the feature or toss it.

Another scenario (#2):

  1. Set up a git repository somewhere (GitHub, Bitbucket, Beanstalk, etc)
  2. Switch away from develop and master to work on a feature
  3. Someone pushed something to base (develop) and you wish to update your feature branch with this new thing
  4. Merge develop to feature branch and continue working (ideally without conflicts)
  5. Commit to the feature branch
  6. Switch to develop and merge your feature branch
  7. Switch back or toss the feature branch.

The steps in this may seem a bit redundant, but some standards require certain extra steps to ensure quality and control. Also it helps releasing in increments. Anyway, the list of commands per scenario:

#1

#2

Now the awesome: Anytime you’re working with two branches and need to switch between them, you can simply use – instead of copy pasting the name or tabbing to autocomplete. It saved me a lot of annoying mouse-grabbing and tabbing to get feature branches. The minus is a shorthand for git checkout @{-1} – or “last branch used”.

Helping anyone out here? My two cents today! :-)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.