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 6

Practicing with Merging

In this lab, you'll work through some simple branch merging.

PREREQUISITES

This lab assumes that you have done Connected Lab 5: Working with Branches. You should start out in the same directory as that lab.

STEPS

  1. Starting in the same directory that you used for Connected Lab 5, make sure you don't have any outstanding or modified files (nothing to commit). You can do this by running the status command and verifying that it reports “working directory clean.”
    $ git status
  2. If not already on the master branch, switch to it with git checkout master. Create a new one-line file.
    $ echo "Initial content" > file5.c
  3. Stage and commit the file on the master branch.
    $ git add .
    $ git commit -m "adding new file on master"
  4. Start up gitk if it's not already running.
    $ gitk &
  5. Create a new branch, but don't switch to it yet. (You can use whatever branch name you want.)
    $ git branch newbranch
  6. Change the same line in the new file (still on the master branch).
    $ echo "Update on master" > file5.c
  7. Stage and commit that change (still on the master branch).
    $ git add .
    $ git commit -m "update on master"
  8. Switch to your new branch.
    $ git checkout newbranch
  9. On the new branch, make a change to the same line of the same file.
    $ echo "Update on newbranch" > file5.c
  10. Stage and commit the file with the change on the new branch.
    $ git commit -am "update on newbranch"
  11. Switch back to the master branch.
    $ git checkout master
  12. Merge your new branch back into the master branch. (Git ...

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