O'Reilly logo

Professional Git by Brent Laster

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Connected Lab 5

Working with Branches

In this lab, you'll start working with branches by creating a new branch and making changes on it.

PREREQUISITES

This lab assumes that you have done Connected Lab 4: Using Git History, Aliases, and Tags. You should start out in the same directory as that lab.

STEPS

  1. Starting in the same directory that you used for Connected Lab 4, use the git branch command to look at what branches you currently have.
    $ git branch
  2. You see a line that says “* master”. This indicates that there is currently only one branch in your repository: master. The asterisk (*) next to it indicates that it is the current branch (the one you've switched to and are currently working in). If your terminal prompt is configured to show the current branch, it also says “master”.
  3. Before you work with a new branch, you need to update the files in the master branch to indicate that these are the versions on master so it will be easier to see which version you have later. To do this, you can use a similar version of the same way you have been creating and updating other files. Run the following command for each file.
    $ echo "master version" >> filename
  4. Stage and commit the updated files. Because these are files that Git already knows about, you can use the following shortcut command:
    $ git commit -am "master version"
  5. When you work with branches, it can be helpful to see a visual representation of what's in the repository. To do this, you can use the gitk tool that comes with ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required