# Homework 6
## NOTE: IF YOU MESS WITH SOMEBODY ELSE'S BRANCH OR CODE, THIS WILL BE TREATED AS AN ACADEMIC CODE VIOLATION. Please don't do this.
## Problem 1: Git Merge vs Rebase
Tux wants to learn everybody's name, wants everybody to learn his favorite color, and how to use Git. Make sure that you have a git account before trying this.
:::warning
**TASK**
***Gradescope:***
1. Clone the following repo: https://github.com/browncs6/homework6-area/
2. Get all the branches from remote. Check out this stackoverflow thread for help on doing this: https://stackoverflow.com/questions/10312521/how-to-fetch-all-git-branches
3. Create and swich to a new branch from master. Your branch should follow the format `<cs-login>-branch`
4. Edit the `name.txt` file with your cs login. Add and commit the changes with a descriptive (and appropriate) commit message.
5. Merge your branch with `master-conflict-1-branch`, using the "our" strategy for resolving conflict. Put the commit hash in your gradescope. What is the current color in `color.txt`?
6. From `<cs-login>-branch`, create and checkout a new branch which should follow the format `<cs-login>-color-branch`. Tux has decided that his new favorite color is purple. Edit `color.txt` and add and commit the changes.
7. Return to `<cs-login>-branch` and merge the changes from your `<cs-login>-color-branch`, using the "their" strategy for merging. What should the current color be in `color.txt`? Record the hash of this merge again.
8. Finally, merge the branch `master-conflict-3-branch` into `<cs-login>-branch`. What file was changed and what was the change?
9. Now that you're a master of merging, let's try rebasing. Rebase `<cs-login>-branch` to `master-rebase-branch-1`. You will have to manually edit the files and resume several times. Keep your login and Tux's favorite color the same as before the rebase. In `complex.txt`, you can choose which lines to keep, though some must be new. Write the lines that you have in `complex.txt`, and once again write the hash of your final commit.
10. **Note**: If you are not able to accomplish this step, please tar/compress your Git repo and submit it using `cs6-handin`.
Now comes the fun part: push your code to remote. Your upstream should be the same as your current branch i.e. `<cs-login>-branch`. Navigate to github and submit a pull request for `<cs-login>-branch`. Please put appropriate and relevant comments in the right place.
12. What is the difference between merge and rebase? Where should each one be used?
:::
## Problem 2: Cleaning History
Tux forgot to remove his password when committing files. Can you help him?
:::warning
**TASK**
***Gradescope:***
1. Follow the instructions [here](https://rtyley.github.io/bfg-repo-cleaner/#download) to download BFG, which can be used to edit commit history in a git repo. We recommend aliasing the `jar` file to a command. NOTE: You may need to install Java first. Executables for most distributions are available on the [java](https://www.java.com/download) website.
2. The password that Tux inadvertently put in follows a regex pattern! Acceptable patterns are 6 characters long and include
* Her726, Num319, San822, Dar591, Bag213
While unacceptable patterns include any non-alphanumeric characters and patterns such as
* SAj983, Saj98, SAj98b, Aj983, saJ984, aj98, sAj983, s1A39j
Write the regex that you used in you gradescope document.
4. Using the BFG site and this [page](https://gist.github.com/w0rd-driven/60779ad557d9fd86331734f01c0f69f0), remove all instances of the password from the commit history of this [repo](https://github.com/browncs6/homework6-q3). Make sure that after cloning, you checkout your own branch, following the `<login>-branch` convention mentioned before. You don't and should not use `git clone --mirror`
5. On your handin document, submit the number of "dirty" commits and which commits they were, ignoring the initial commit.
:::
## Problem 3: Building a website: Part 2
:::warning
**TASK**
***Gradescope:***
Using the official [documentation](https://help.github.com/en/articles/getting-started-with-github-pages), use Github to host the website you made last week! Create your own repo, and when you're finished, submit the link to your website on your Gradescope document.
:::
## Problem 4: Git Hooks
Tux gets bored fromy trying to format his HTML code help him do it automatically.
:::warning
**TASK**
***Gradescope:***
1. Clone your own repository that you used to make your website to your local machine.
2. Access the `.git` folder
3. You should see a `hooks` folder here. Access it.
4. While there are multiple types of hooks, we will be using `pre-commit` one. You can find out more about the rest of the hooks and how to use them on this [page](https://www.atlassian.com/git/tutorials/git-hooks).
5. We'll be trying to make an HTML autoformatter. Download [prettier](https://prettier.io/docs/en/install.html), which will help us format the code. Try using the `npm` method on the installation page.
6. Try to write the autoformatter. This should *only run* on code that has been changed and staged. Use `git diff` to find files that changed (You may need to look at the help/man pages.) If you installed `prettier`properly, it should be invokable just as `prettier --write` to change files. Remember to `add` the files at the end once the formatting has completed! Your script should return the proper exit code.
7. Copy your entire git repository to the department machines using `scp` and hand it in using `cs6-handin hw6`.