Unit 7 Practice: GitHub Solution

Note: If the instructions can be completed via the terminal, we will list it here. Otherwise, assume the solution has to do with the browser, text editor, or IDE.

Go to the Learn Code Unit 7 repository on GitHub.

  1. Fork the repository to your account. For solution, see forking.
  2. Clone your forked repository to local. (Use the terminal.)
    $ git clone https://github.com/your_username/learn-code-unit-7)
    # where your_username is replaced with your GitHub username
    

Open an IDE or text editor application and do the following (from now on you can choose to complete the instructions using the application’s GUI or using the command line):

  1. Make a new directory called practice in the root directory and change into it.
    # Make sure you are in the root directory
    $ mkdir practice
    $ cd practice
    
  2. Create a new file called hello.txt and add the following: “Hello world, I’m a programmer”.
    $ touch hello.txt
    $ echo "Hello world, I'm a programmer" > hello.txt
    
  3. Add and commit the changes with the message "Add hello.txt".
    $ git add hello.txt
    $ git commit -m "Add hello.txt"
    
  4. Push the changes to your remote master branch.
    $ git push
    # git push origin master is also fine, but unnecessarily long
    
  5. Checkout the feature branch.
    $ git checkout feature
    
  6. Add the line “Java is an object-oriented programming language” to hello.txt.
    $ echo "Java is an object-oriented programming language" >> hello.txt
    
  7. Add and commit the changes with the message "Add Java description".
    $ git add hello.txt
    $ git commit -m "Add Java description"
    ## ALTERNATE SOLUTION ##
    $ git commit -am "Add Java description"
    
  8. Checkout the master branch.
    $ git checkout master
    
  9. Replace the line “Hello world, I’m a programmer” in hello.txt with 2 lines:
    This is the way the world ends
    Not with a bang, but a whimper
    
    $ echo "This is the way the world ends" > hello.txt
    $ echo "Not with a bang, but a whimper" >> hello.txt
    
  10. Add and commit the changes with the message "Add poem lines".
    $ git add hello.txt
    $ git commit -m "Add poem lines"
    ## ALTERNATE SOLUTION ##
    $ git commit -am "Add poem lines"
    
  11. Merge feature into master. Resolve the conflict so that hello.txt looks like this:
    Hello world, I'm a programmer
    This is the way the world ends
    Not with a bang, but a whimper
    
    $ git merge feature
    # at this point, you need to resolve the conflict
    # with some sort of editor
    $ git add hello.txt
    $ git commit
    # you can also use git commit -am to skip the git add
    ## ALTERNATE SOLUTION ##
    $ git merge feature
    $ echo "Hello world, I'm a programmer" > hello.txt
    $ echo "This is the way the world ends" >> hello.txt
    $ echo "Not with a bang, but a whimper" >> hello.txt
    $ git add hello.txt
    $ git commit
    # you can also use git commit -am to skip the git add
    
  12. Push the changes to your remote master branch.
    $ git push
    # git push origin master is also fine, but longer
    

Go to the official Learn Code Unit 7 repository.

For solution to steps 1-3 below, see pull requests.

  1. Create a new pull request by comparing omega9656:master with your_username:master (where your_username is replaced by your GitHub username).
  2. Be sure to include a concise title and description of what changed.
  3. Label your pull request with the green practice label.