# First git project ## 1. configuring name, email and editor git config --global user.name "John Doe" git config --global user.email "johndoe@example.com" # Note: if using VSCode, the "--wait" option # allows git to understand when you are finished # editing a text file git config --global core.editor "code --wait" # If you see the message: # Aborting commit due to empty commit message. # when doing 'git commit', look up online how to use your # editor together with git (the message is because the # editor did not properly save the file before exiting). ## 2. creating a directory mkdir test_project ## 3. creating a git repository cd test_project/ git init ## 4. creating main.c and Makefile # The normal/easy way is to create new files in a text editor, # copy/paste their content from the question, then save them in the # appropriate directory (test_project/main.c, test_project/Makefile) # Make sure that your editor uses actual TAB characters in the Makefile # This can be verified with 'hexdump -C Makefile': the TAB character # have ASCII code 9 # If you prefer to do it from the terminal, you could use these commands to create them: printf '#include \n\n\nint main()\n{\n\tprintf("Hello, world!\\n");\n\treturn 0;\n}\n' > main.c printf 'main: main.o\n\tclang -Wall -O3 -o $(@) $(^)\n\nmain.o: main.c\n\tclang -Wall -O3 -c -o $(@) $(<)\n' > Makefile ## 5. build the executable main and create .gitignore make # Preferably, we create a file containing the following lines: # *.o # /main # and save it as test_project/.gitignore # Alternatively, printf '*.o\n/main\n' > .gitignore ## 6. Stage git add -A git status ## 7. Commit git commit -m 'First commit of test_project.' # Second git project ## 1. Clone Alice's repository git clone https://www.poirrier.ca/git/mathprog.git/ cd mathprog/ ## 2. Fetch and checkout Bob's commit git fetch https://www.poirrier.ca/git/bob.git git log # does not show Bob's commit git log --all # still does not show Bob's commit git checkout 79dcd1 # or equivalently, git checkout FETCH_HEAD git log # now Bob's commit appears # If we want, we can already merge Bob's code into "main" now (in # this case, this only amounts to advancing the "main" branch # to Bob's commit). To do that, we would # git checkout main # go back to main # git merge 79dcd1 # merge Bob's commit ## 3. Fetch, checkout and merge Carol's branch # Fetch Carol's repository git fetch https://www.poirrier.ca/git/carol.git git log # nothing from Carol appears git branch # carol_branch does not appear # Fetch Carol's repository (again), # but this time also the branch "carol_branch". # We call it the same locally. git fetch https://www.poirrier.ca/git/carol.git carol_branch:carol_branch git branch # carol_branch now appears git checkout carol_branch git log git checkout main # we go back to "main" to do the merge git log # without --all, only ancestor commits appear git log --all # with --all, we see the three commits git log --all --graph # with --graph in addition, we see how they # relate to each other git merge carol_branch # merge Carol's commit; in this case too # this just amounts to advancing "main" ## 4. Fix output bug # In the MathProg constructor, apply the following change (line 66): # - if not nosolve: # + if nosolve: git diff # observe what you changed git add -A # stage your change git diff --staged # observe what is staged # (i.e., what you are about to commit) git commit -m "Fixed logic bug with nosolve parameter." ## 5. Fetch Dan's work, rebase it # This time for conciseness, we directly fetch "dan_branch" # in addition to the commits. git fetch https://www.poirrier.ca/git/dan.git dan_branch:dan_branch git log --all --graph # we observe the divergence # but we decide we don't want a divergence # for this in our commit history, so we # will rebase Dan's change on top of ours git checkout dan_branch git rebase main git log --all --graph # now there is no divergence git checkout main # go back to main to merge "dan_branch" git merge dan_branch # again, this is just advancing "main" git log --all --graph ## 6. Fetch Eve's work, merge it, resolve conflict git fetch https://www.poirrier.ca/git/eve.git eve_branch:eve_branch git log --all --graph # again a divergence git checkout eve_branch # we checkout Eve's branch to look at # her code. This time, we decide that we want # to keep the divergence in our commit history git checkout main # we go back to main git merge eve_branch # and merge Eve's branch # we have merge conflicts git status # Open mathprog.py, locate the conflict markers (>>>>>, <<<<<). # We resolve the conflicts. That is, we choose which version of the # conflicting lines of code we want to keep. In this case, we # prefer the "eve_branch" version of the code over the one in "HEAD", # for both conflicts. git add -A git commit