# 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/alice.git/ cd alice/ ## 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 a97f91 # or equivalently, git checkout FETCH_HEAD git log # now Bob's commit appears ## 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, and also the branch "carol_branch". # 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 git log git log --all git merge carol_branch ## 4. Fix output bug # In the run() function, apply the following change: # - print(' ' # + print('# ' git diff # observe what you changed git add -A # stage your change git diff --staged # observe what is staged (what you are about to commit) git commit -m "Fixed output bug." ## 5. Fetch Eve's work, rebase it git fetch https://www.poirrier.ca/git/eve.git carol_branch:carol_branch git log --all --graph git checkout carol_branch git rebase main git log --all --graph git checkout main git merge carol_branch git log --all --graph ## 6. Fetch Dan's work, merge it, resolve conflict git fetch https://www.poirrier.ca/git/dan.git dan_branch:dan_branch git log --all --graph git merge dan_branch git status # open table.py, locate the conflict markers (>>>>>, <<<<<) # resolve conflict, then: git add -A git commit