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.
- Fork the repository to your account. For solution, see forking.
- 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):
- 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
- 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
- Add and commit the changes with the message
"Add hello.txt"
.$ git add hello.txt $ git commit -m "Add hello.txt"
- Push the changes to your remote
master
branch.$ git push # git push origin master is also fine, but unnecessarily long
- Checkout the
feature
branch.$ git checkout feature
- Add the line “Java is an object-oriented programming language” to
hello.txt
.$ echo "Java is an object-oriented programming language" >> hello.txt
- 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"
- Checkout the
master
branch.$ git checkout master
- 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
- 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"
- Merge
feature
intomaster
. Resolve the conflict so thathello.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
- 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.
- Create a new pull request by comparing
omega9656:master
withyour_username:master
(whereyour_username
is replaced by your GitHub username). - Be sure to include a concise title and description of what changed.
- Label your pull request with the green
practice
label.