diff --git a/Labs/Lab2/git-conflict/README.md b/Labs/Lab2/git-conflict/README.md new file mode 100644 index 0000000000000000000000000000000000000000..a2007eebfcb7681c2c8a42fc6291fe43f31fef6f --- /dev/null +++ b/Labs/Lab2/git-conflict/README.md @@ -0,0 +1,54 @@ +# Git Merging (and conflicts) + +1. In an SSH session, run `export EDITOR=nano` so that `nano` is your default editor for the following practice. + +2. Clone the directory first. If you have already cloned it, `cd` into the directory and then run `git pull` to update the directory. + +3. Navigate (with `cd`) to `labs/git-conflict` within the semester repo. Run `unzip repo.zip` to create a `repo` directory, which contains an `adder.py` program. (If you cannot run `unzip` correctly, try to install unzip by running `sudo apt-get install unzip`. Enter "9" for the prompt.) + +4. `cd` to the `repo` directory and run the program: `python3 adder.py`. + +5. Use `ls` and `cat` (or `nano`) to browse the file(s) in the repo. + +6. Run `git branch`, making a note of what branch the HEAD is currently on (the `*` indicates the `HEAD`). Make a note of the other branches. + +7. Your job is to merge the other branches into the main branch, using `git merge ????` commands. After each merge, check what files are in the directory you're working and what they contain. + +**Notes:** + +* The first merge you do will be easiest, because it is a roll forward merge. Each of the three branches share a common history with `main`, so `main` can just catch up with the latest commits +* The changes on the `docs` branch are on a separate file (README.txt), so that will never conflict with the other changes +* There will be a conflict once you've tried to merge both `args` and `func-rename`. Resolve it like we did in class. + +**Conflict resolution hints:** + +* Use `nano` to open the file with the conflict. The file will contain conflicting code. Edit everything so you have the version you want, and the extra characters added by git are removed. +* Whenever you aren't sure of the next step, run `git status` to get the hint about how to "mark resolution" or "conclude the merge" + +When you're all done, the `adder.py` program should look like this: + +```python +import sys + +print("Welcome to the adder program!") + +def add(x, y): + print(f"{x} plus {y} is {x+y}") + +if len(sys.argv) == 3: + add(int(sys.argv[1]), int(sys.argv[2])) +else: + print("Usage: python3 adder.py <x> <y>") + +print("Bye") +``` + +And it should be runnable like this (promt will vary): + +``` +PROMPT$ python3 adder.py 3 5 +Welcome to the adder program! +3 plus 5 is 8 +Bye + +``` diff --git a/Labs/Lab2/git-conflict/repo.zip b/Labs/Lab2/git-conflict/repo.zip new file mode 100644 index 0000000000000000000000000000000000000000..7fd7eebeb074a4d52f32fcbcf16af8b02ab850b4 Binary files /dev/null and b/Labs/Lab2/git-conflict/repo.zip differ diff --git a/Labs/Lab2/git-pr/0.png b/Labs/Lab2/git-pr/0.png new file mode 100644 index 0000000000000000000000000000000000000000..4eeee24ef32aabb5e84bf7e84b3080e1cdeffc41 Binary files /dev/null and b/Labs/Lab2/git-pr/0.png differ diff --git a/Labs/Lab2/git-pr/1.png b/Labs/Lab2/git-pr/1.png new file mode 100644 index 0000000000000000000000000000000000000000..dfed87d7bcffde31d61f5c011fcb7cb65eee6e6e Binary files /dev/null and b/Labs/Lab2/git-pr/1.png differ diff --git a/Labs/Lab2/git-pr/10.png b/Labs/Lab2/git-pr/10.png new file mode 100644 index 0000000000000000000000000000000000000000..a7ea7611989066e559acac405cc66156689d405c Binary files /dev/null and b/Labs/Lab2/git-pr/10.png differ diff --git a/Labs/Lab2/git-pr/11.png b/Labs/Lab2/git-pr/11.png new file mode 100644 index 0000000000000000000000000000000000000000..94055d57419dba6fec622cf099312a5bf1103ec9 Binary files /dev/null and b/Labs/Lab2/git-pr/11.png differ diff --git a/Labs/Lab2/git-pr/2.png b/Labs/Lab2/git-pr/2.png new file mode 100644 index 0000000000000000000000000000000000000000..95a40c8e2e6dce9fc091b5b104c5433c11da10a0 Binary files /dev/null and b/Labs/Lab2/git-pr/2.png differ diff --git a/Labs/Lab2/git-pr/3.png b/Labs/Lab2/git-pr/3.png new file mode 100644 index 0000000000000000000000000000000000000000..f70ef27fe879387cc6fcbcafed9f317e6f6bd2e0 Binary files /dev/null and b/Labs/Lab2/git-pr/3.png differ diff --git a/Labs/Lab2/git-pr/4.png b/Labs/Lab2/git-pr/4.png new file mode 100644 index 0000000000000000000000000000000000000000..9b391f811ff95532814587cae8a0060cb2270b4f Binary files /dev/null and b/Labs/Lab2/git-pr/4.png differ diff --git a/Labs/Lab2/git-pr/5.png b/Labs/Lab2/git-pr/5.png new file mode 100644 index 0000000000000000000000000000000000000000..e5c6968d02ab7f91a776270c0cdaf7c5b9703e18 Binary files /dev/null and b/Labs/Lab2/git-pr/5.png differ diff --git a/Labs/Lab2/git-pr/6.png b/Labs/Lab2/git-pr/6.png new file mode 100644 index 0000000000000000000000000000000000000000..35cf8a0562957506a2d9394b33d3af8401743c8e Binary files /dev/null and b/Labs/Lab2/git-pr/6.png differ diff --git a/Labs/Lab2/git-pr/7.png b/Labs/Lab2/git-pr/7.png new file mode 100644 index 0000000000000000000000000000000000000000..cce1432c2324c2d9d349919a95717a0b4afd245b Binary files /dev/null and b/Labs/Lab2/git-pr/7.png differ diff --git a/Labs/Lab2/git-pr/8.png b/Labs/Lab2/git-pr/8.png new file mode 100644 index 0000000000000000000000000000000000000000..5f5735176016b76c3ca8ab5b66d6e28e5c8dc695 Binary files /dev/null and b/Labs/Lab2/git-pr/8.png differ diff --git a/Labs/Lab2/git-pr/9.png b/Labs/Lab2/git-pr/9.png new file mode 100644 index 0000000000000000000000000000000000000000..0c92b651fd4e38271259c896597c2754ce0b6bcd Binary files /dev/null and b/Labs/Lab2/git-pr/9.png differ diff --git a/Labs/Lab2/git-pr/PR_list.png b/Labs/Lab2/git-pr/PR_list.png new file mode 100644 index 0000000000000000000000000000000000000000..3734cc0c9db2521959a893e3cb693e8f717e91f0 Binary files /dev/null and b/Labs/Lab2/git-pr/PR_list.png differ diff --git a/Labs/Lab2/git-pr/README.md b/Labs/Lab2/git-pr/README.md new file mode 100644 index 0000000000000000000000000000000000000000..07cbd82441cdcb89baa7266b9f743a122cb93d11 --- /dev/null +++ b/Labs/Lab2/git-pr/README.md @@ -0,0 +1,113 @@ +# GitLab + +In this lab, you'll practice using git. You'll create your own repo, and push changes there. + +## Background + +A **repo** contains a bunch of commits, and usually a few branches to +label different commits. In order to support collaboration and +offline work, it is common to have multiple copies of the same repo. +For example, say there is a team of 3 people working on an open-source +project. There will probably be six copies of the repo: one on each +person's laptop or virtual machine and one on each person's GitLab +account (with one of the GitLab ones being the primary home for the +code). + +Various git commands and tools can be used to syncronize the copies. +For example, running `git push origin test` uploads the `test` branch, +and all the associated commits, to `origin`: + +<img src="0.png" width=800> + +`origin` is an example of a **remote**, a shorthand name to use instead +of a full URL for a repo somewhere else (like GitLab). When you +`clone` a repo from GitLab, you automatically get a remote called +`origin`, but you can setup more yourself. + +`clone` is a one-time thing to make a new copy of a GitLab repo on +your computer and download all the commits/branches/etc. If new +changes are made on the GitLab repo, you can instead run `git pull` to +download these without creating a whole new copy of the repo. + +In addition to these three general git commands (**clone**, **pull**, **push**), +GitLab has two key tools for syncing repos: + +* **fork**: copy somebody else's GitLab repo to a new repo (called a fork) on your account +* **pull request**: ask somebody to bring some new code you uploaded to your fork back into the main repo + +Consider a concrete example of how to use all these commands. Say you find a bug in `pandas`, fix it, and want to share the fix back. You might do the following: + +1. Find the pandas repo on GitLab +2. Clone the pandas repo to a copy on your computer +3. Fork the pandas repo to a copy in your own GitLab account +4. Make the change to the copy on your computer +5. Add a remote so that you can push from your computer to your GitLab fork +6. Do a push to upload your changes from your computer to your fork +7. Do a pull request from your fork to the main pandas repo +8. Somebody in charge of main repo will consider your changes, and probably (a) click a button on GitLab to incorporate your changes, or (b) give you feedback to make the code better first, in which case you go back to step 4 + +## Step 2: SSH Keys + +These steps are similar to the previous lab. There, we created SSH keys +on your laptop, allowing you to connect laptop=>VM. Now, we're +creating SSH keys on your VM, allowing you to connect VM=>GitLab. + +Connect via SSH to your VM. + +Run `ssh-keygen` on your VM and repeatedly hitting `ENTER` to accept +all the defaults (including an empty password). + +Run the following and **copy** the output: + +``` +cat ~/.ssh/id_rsa.pub +``` + +Select "New SSH key". + +Name the key "cs320-vm" (or whatever you like, really) and paste the +contents of `id_rsa.pub` to the "Key" box. + +Click "Add SSH Key" to finish adding it. + +## Step 3: Create a Repo + +Create a public repo called +"cs320-lab2". Do NOT initialize the repo by clicking on any checkbox at this step. Do NOT select "Add a README file". + +This should create a repo. Go to that repo. Click the **Clone** button, and then click **ssh**. Copy the commands in it. We want to run those in a new directory on your computer. So run this in the terminal: + +``` +mkdir cs320-lab2 +cd cs320-lab2 +``` + +Then paste and run `git clone ` + what you copied from GitLab. You shouldn't be +asked for a password (if so, double check you did the parts of step +2+3 related to SSH correctly). If you see "Are you sure you want to +continue connecting?", type "yes" and ENTER. + +If prompted, you can configure your username/email: + +``` +git config --global user.name "your_gitLab_username" +git config --global user.email "your_email" +``` + +Refresh the GitLab page for your repo. You should now see the first commit. + +Make another change to README.md on your computer (for example, say +"hello world"), push those changes to GitLab, then refresh the page. +Like this (one step at a time): + +``` +nano README.md # make some changes, then save +git status +git add README.md +git commit -m 'say hello' +git push +``` + +Keep in mind `nano` is an in-terminal text editor so you can only use +keyboard shortcuts (not the mouse). Do control-O to write the file. +"^" means CONTROL, and the bottom of the screen should provide hints. \ No newline at end of file diff --git a/Labs/Lab2/git-sim/1.png b/Labs/Lab2/git-sim/1.png new file mode 100644 index 0000000000000000000000000000000000000000..610a8c802f7cdd5d441b669667916f84df3c7f1f Binary files /dev/null and b/Labs/Lab2/git-sim/1.png differ diff --git a/Labs/Lab2/git-sim/2.png b/Labs/Lab2/git-sim/2.png new file mode 100644 index 0000000000000000000000000000000000000000..4c0a19925b123e52af12afd68ee49c95c18b867d Binary files /dev/null and b/Labs/Lab2/git-sim/2.png differ diff --git a/Labs/Lab2/git-sim/README.md b/Labs/Lab2/git-sim/README.md new file mode 100644 index 0000000000000000000000000000000000000000..163e55a9cd161eea74927769f6358ab8a215ab5d --- /dev/null +++ b/Labs/Lab2/git-sim/README.md @@ -0,0 +1,25 @@ +# Git Simulator + +Let's start by practicing in the Git simulator <a +href="https://tyler.caraza-harter.com/cs320/learnGitBranching/index.html" +target="_blank">here</a>. Try to run commands to get to the following state (if you get stuck, check the [solution here](solution.md)): + +<img src="1.png" width=500> + +Useful commands for the above problem: +* `git commit`: make a new commit +* `git branch bname`: create a branch named `bname` +* `git checkout bname`: move `HEAD` to the commit referenced by the `bname` +* `git checkout c1`: move `HEAD` to the `c1` commit +* `git merge bname`: merge changes on the `bname` branch into the current branch +* `git branch -D bname`: delete the branch named `bname` + +If you have some free time at the end of the lab, you can try out the following challenge. + +Try to get to this state (no answer to check for this one, so you'll need to work for it!): + +<img src="2.png" width=500> + +**Hint:** Start by creating commits on four branches, b1, b2, b3, and b4. +Merge b2 into b1 and b4 into b3. Then merge the two merge commits +with a third merge commit. diff --git a/Labs/Lab2/git-sim/solution.md b/Labs/Lab2/git-sim/solution.md new file mode 100644 index 0000000000000000000000000000000000000000..55fc05997840dc88f8ad247aaf2dd948f479eb7b --- /dev/null +++ b/Labs/Lab2/git-sim/solution.md @@ -0,0 +1,20 @@ +# Solution + +## Steps: + +1. git commit +2. git checkout c1 +3. git branch test +4. git checkout test +5. git commit +5. git commit +6. git checkout c3 +7. git checkout -b feature +8. git commit +9. git checkout test +10. git merge feature +11. git branch -D feature + +## Result: + +<img src="./1.png" width=600> diff --git a/Labs/Lab2/lab2.md b/Labs/Lab2/lab2.md new file mode 100644 index 0000000000000000000000000000000000000000..0530a3c5efcc14a3c85bd35e2b48369211075949 --- /dev/null +++ b/Labs/Lab2/lab2.md @@ -0,0 +1,7 @@ +# Lab 3: Git + +1. Practice using the [Git Simulator](./git-sim) + +2. Try [merging branches](./git-conflict) and conflict resolution + +3. Learn how to create [your own repo](./git-pr)