♣ Due Date: One week from the posting date @ 10:30 AM. This homework aims at giving you some experience on how to create Git branches, develop your project on multiple branches, merge them, resolve potential conflicts between different branches upon merging, and finally how to delete them. It also gives you some experience with using other commonly-used Git commands.
First, use the following Markdown language references, or any other reference that you find or prefer, to design a Github-interpretable README file for each of folders in your project for this course, and a Github web-page for your project.
- Markdown language cheat-sheet (pdf)
- Markdown language reference (web)
- Adam Pritchard’s Markdown cheat-sheet (web)
Write your code sections of your answer in Markdown syntax.
For example,
```bash
$ git branch -d test
error: Cannot delete branch 'test' checked out at 'C:/Users/Amir/git/foo'
```
will display the following text highlighted as bash code, in your readme.md file.
$ git branch -d test
error: Cannot delete branch 'test' checked out at 'C:/Users/Amir/git/foo'
1. Include the following information with the following format and information in your main directory readme.md
file:
Beginning of the README file’s content
MAPCP2019U - Introduction to Computer Programming (Summer 2019)
Name: <first name> <last name>
UTA EID: <your UTA EID>
Email: <your email>
Department: Department of Physics
University: The University of Texas at Arlington
Level: graduate - <Freshman (1st year) / Sophomore (2nd year) / Junior (3rd year) / Senior (4th year) / Dinosaur (5th year and above) >
MAPCP-Class Title: Student
Course Webpage: https://www.cdslab.org/MAPCP2019U/
Photo:
Description of the project’s content
This repository contains my homework, quizzes, and virtually every effort that I have made for MAPCP2019U class. The structure of the project is the following:
- homework: (the homework hyperlink should take the reader to the homework folder)
This directory contains all my homework submissions, each of which is a folder properly named with homework number, containing the homework submission.
- quiz: (the quiz hyperlink should take the reader to the quizzes folder)
This directory contains all my quiz submissions, each of which is a folder properly named with quiz number, containing the quiz submission.
- exam: (the exam hyperlink should take the reader to the exams folder)
This directory contains all my exam submissions, each of which is a folder properly named with exam name or number, containing the exam submission.
For questions and troubleshooting, please contact:
<your name>
<your email>
<any other contact or signature information that you would like to add>
I have not failed. I’ve just found 10,000 ways that won’t work.
Thomas A. Edison
End of the README file’s content
Answer:
Use the following Markdown code in your readme.md
file to get the exact same behavior as requested above:
#### MAPCP2019U - Introduction to Computer Programming (Summer 2019)
<br>
**Name:** \<first name> \<last name>
**UT EID:** \<your UTA EID>
**Email:** \<your email>
**Department:** [Department of Physics](https://www.uta.edu/physics/)
**University:** [The University of Texas at Arlington](https://www.utexas.edu/)
**Level:** graduate - \<Freshman (1st year) / Sophomore (2nd year) / Junior (3rd year) / Senior (4th year) / Dinosaur (5th year and above) >
**MAPCP-Class Title:** Student
**Course Webpage:** <https://www.cdslab.org/MAPCP2019U/>
**Photo:**
![Amir Shahmoradi](../../images/AmirShahmoradi.png)
#### Description of the project's content
<br> This repository contains my homework, quizzes, and virtually every effort that I have made for [MAPCP2019U class](https://www.cdslab.org/MAPCP2019U/). The structure of the project is the following:
* **[homework](#homework):** (the homework hyperlink should take the reader to the homework folder)
This directory contains all my homework submissions, each of which is a folder properly named with homework number, containing the homework submission.
<br>
* **[quiz](#quiz):** (the quiz hyperlink should take the reader to the quizzes folder)
This directory contains all my quiz submissions, each of which is a folder properly named with quiz number, containing the quiz submission.
<br>
* **[exam](#exam):** (the exam hyperlink should take the reader to the exams folder)
This directory contains all my exam submissions, each of which is a folder properly named with exam name or number, containing the exam submission.
<br>
For questions and troubleshooting, please contact:
\<your name>
\<your email>
\<any other contact or signature information that you would like to add>
>I have not failed. I've just found 10,000 ways that won't work.
>[Thomas A. Edison](https://en.wikipedia.org/wiki/Thomas_Edison){:target="_blank"}
Note that you will have to change the relevant information and hyper-references in the above Mardown code to those that match your own information in your own repository (including your own photo).
2. Create two additional test branches in your project, each of which is branched directly from master. For each of the following cases, write the command and the corresponding output message of Git, in Markdown language in a readme.md
file inside your homework/1/
folder in your master branch. If you don’t have this folder in your project, then create the folder and then place your initial readme.md
file in this folder with your signature as the content of the file. Then stage and commit this file together with homework-1 folder to your local repository. Throughout the rest of this homework, you will fill this readme.md
file with your answers.
(A) Create two branches, both from your master branch, with names test1 and test2.
Answer:
$ git branch
* master
$ git branch test1
$ git branch test2
$ git branch
* master
test1
test2
(B) Now checkout the test1 branch and create a new text file named test.txt
in the homework/1/
directory of this branch.
Answer:
$ git checkout test1
Switched to branch 'test1'
$ git status
On branch test1
nothing to commit, working tree clean
$ ls
readme.md
$ touch test.txt
$ ls
readme.md test.txt
(C) Inside test.txt
in test1 branch write this message: This is some example text for branch test1, and save it.
Answer:
Use vim test.txt
to open vim editor. Press shift + I
to switch to vim insert mode. write This is some example text for branch test1 in test.txt
file. Now, Press ESC
key and write :wq
on the vim command line to save the file and quit vim.
(D) Now stage and commit test.txt
file to branch test1.
Answer:
$ git status
On branch test1
Untracked files:
(use "git add <file>..." to include in what will be committed)
test.txt
nothing added to commit but untracked files present (use "git add" to track)
$ git add --all
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory.
$ git commit -m"commiting the test.txt file in test1 branch"
[test1 715ca59] commiting the test.txt file in test1 branch
1 file changed, 1 insertion(+)
create mode 100644 test.txt
$ git status
On branch test1
nothing to commit, working tree clean
(E) Checkout the branch test2. Do you still see test.txt
that you just created in your homework/1/
directory? You can search for it by the bash command ls
. Explain why you see/don’t see the file in your working directory anymore.
Answer:
$ git checkout test2
Switched to branch 'test2'
$ ls
readme.md
The test.txt
files is not in the project’s working directory, since I just chaecked out a new branch test2 that does not contain any files that were generated and committed in test1 branch.
(F) Create a new text file named test.txt
in the homework/1/
directory of this branch as well, and add This is some example text for branch test2 to its content.
Answer:
$ touch test.txt
$ vim test.txt
$ git status
On branch test2
Untracked files:
(use "git add <file>..." to include in what will be committed)
test.txt
nothing added to commit but untracked files present (use "git add" to track)
The procedure for adding content to the file is very similar to that in part (C) of the problem, explained above.
(G) Now try to checkout test1. What error/warning message do you get? Fix the source of error and then checkout test1 branch.
Answer:
$ git checkout test1
error: The following untracked working tree files would be overwritten by checkout:
test.txt
Please move or remove them before you switch branches.
Aborting
$ git add --all
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory.
$ git commit -m"commtting the test2 branch changes"
[test2 fce6a94] commtting the test2 branch changes
1 file changed, 1 insertion(+)
create mode 100644 test.txt
$ git status
On branch test2
nothing to commit, working tree clean
$ git checkout test1
Switched to branch 'test1'
(H) Now merge the content of test1 with master branch. (Hint: Note from which branch you doing this merge!)
Answer:
$ git checkout master
Switched to branch 'master'
$ ls
readme.md
$ git status
On branch master
nothing to commit, working tree clean
$ git merge test1
Updating a661e87..715ca59
Fast-forward
test.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 test.txt
(I) Now what do you see as the content of master branch? (Hint: Use ls
bash command, to list the files in the working directory.)
Answer:
$ ls
readme.md test.txt
$ git status
On branch master
nothing to commit, working tree clean
(J) Now merge the content of test2 with master branch. What error/warning message do you get? Why does this error arise?
Answer:
$ git merge test2
Auto-merging test.txt
CONFLICT (add/add): Merge conflict in test.txt
Automatic merge failed; fix conflicts and then commit the result.
(K) Now checkout test2. What error/warning message do you get?
Answer:
$ git checkout test2
test.txt: needs merge
error: you need to resolve your current index first
(L) Run the Git command git status
. Why does such a conflict exist, as mentioned in git status
output?
Answer:
Basically, by running git merge test2
command, we attempted to merge test.txt file of test2 branch with the existing test.txt
file of master branch. But the content of the two is different.
(M) At this stage, you have two options: Either 1. stage and commit the combined conlifting test.txt
file to Git repository (but this is not recommended), or, 2. open the file test.txt
using vim editor on the command line and reslve the conflict by editing the content of the file to only this sentence: . Then save and quit *vim.
Answer:
$ vim test.txt
$ cat test.txt
This is some example text from both test1 and test2 branches combined.
The bash command cat
shows the content of text.txt
file.
(N) Now, run git status
, then stage and commit your conflict-resolved file. Then checkout test2 branch.
Answer:
$ git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both added: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ git add test.txt
$ git commit -m"adding the test.txt resolution file"
[master 4c74098] adding the test.txt resolution file
$ git status
On branch master
nothing to commit, working tree clean
$ git checkout test2
Switched to branch 'test2'
(O) Now, try deleting branch test1, while on branch test2. What error/warning message do you get?
Answer:
$ git branch -d test1
error: The branch 'test1' is not fully merged.
If you are sure you want to delete it, run 'git branch -D test1'.
(P) Now, switch back to master branch. Now, try deleting branch test1, while on master branch. What message do you get from Git? List all the existing branches using git branch
command.
Answer:
$ git checkout master
Switched to branch 'master'
$ git branch
* master
test2
(Q) Why is there such a difference in Git messages between when you tried deleting test1 branch from test2 branch, and when you tried deleting test1 branch from master branch?
Answer:
The difference arises, because whichever branch you are in, Git assumes that the content of any other branch should be first merged for the current branch before deteting the other branch. Therefore, in the first case, Git warns that there is unmerged data between test1 and test2 branches. But the delete command from master branch gives no error, since the content of test1 branch has been previously appropriately merged with master branch.
(R) Now checkout test2 branch. While on test2, try to delete branch test2. What error/message do you get?
Answer:
$ git checkout test2
Switched to branch 'test2'
$ git branch -d test2
error: Cannot delete branch 'test2' checked out at '~/test'
(S) Switch back to master and delete test2 branch. List all your project branches by the appropriate Git command.
Answer:
$ git checkout master
Switched to branch 'master'
$ git branch -d test2
Deleted branch test2 (was fce6a94).
$ git branch
* master
(T) Stage and commit all the changes (including the file test.txt
) to your project’s master branch. Now push it all to the remote repository by Wednesday Feb 15 2017, 9:00 a.m. CDT.
Answer:
$ git add --all
$ git commit
On branch master
nothing to commit, working tree clean
$ git push --all
3. (Bonus, not mandatory) Design a simple Github page for your project, using the main directory’s readme.md
file. Submit the link to the page as your answer. Note that you don’t need to add anything extra to your readme file.
Answer:
Ask me in class to teach you how to do it.
4. (Bonus, not mandatory) Create a website for your project, such that your project is accessible through its web address based on the content of your project’s website, not based on the content of master branch.
Answer:
Ask me in class and I will explain how to do it.