Some more Git exercise

  1. Please read about git merge conflicts

  2. Now read about resolving a merge conflict using the command line

  3. Now let’s create a merge conflict

# cd to your local git folder
cd ~/GitFolders/Math-7360-Xiang-Ji

# checkout master branch
git checkout main

# list files
ls -lt

# check git status
git status

# check branch
git branch
## bash: line 1: cd: /Users/xji3/GitFolders/Math-7360-Xiang-Ji: No such file or directory
## Already on 'main'
## Your branch is up to date with 'origin/main'.
## total 2928
## -rw-r--r--@ 1 xji3  staff    2188 Sep 20 15:02 lab_04_git.Rmd
## -rw-r--r--@ 1 xji3  staff  742832 Oct 10  2021 lab_04_solutions.html
## -rw-r--r--@ 1 xji3  staff    3992 Oct 10  2021 lab_04_solutions.Rmd
## -rw-r--r--@ 1 xji3  staff  744264 Oct  7  2021 lab_04_git.html
## On branch main
## Your branch is up to date with 'origin/main'.
## 
## Untracked files:
##   (use "git add <file>..." to include in what will be committed)
##  ../../HW/HW1/HW1_Fall_2023.aux
##  ../../HW/HW1/HW1_Fall_2023.log
##  ../../HW/HW1/HW1_Fall_2023.synctex.gz
##  ../../HW/HW1/HW1_Fall_2023.tex
##  ../../HW/HW1/HW1_XJ.Rmd
##  ../../HW/HW1/HW1_XJ.html
##  ../../HW/HW1/HW1_keys.Rmd
##  ../../HW/HW1/HW1_keys.html
##  ../../HW/HW2/CRDT Data - CRDT.csv
##  ../../HW/HW2/HW2_keys.Rmd
##  ../../HW/HW2/HW2_keys.html
##  ../../HW/HW2/LA_COVID_AGE_GENDER_BYWEEK_PUBLICUSE.xlsx
##  ../../HW/HW2/LA_COVID_TESTBYDAY_PARISH_PUBLICUSE.xlsx
##  ../../HW/HW2/LA_COVID_TESTBYWEEK_TRACT_PUBLICUSE.xlsx
##  ../../HW/HW2/louisiana-history.csv
##  ../../HW/HW2/louisiana-race-ethnicity-historical.csv
##  ../../HW/HW2/old/
##  ../../HW/HW2/week.6.plot.jpg
##  ../../HW/HW2/week6.png
##  ../../HW/HW3/
##  ../../_layouts/Math7360_fall2023_logo.png
##  ./
## 
## nothing added to commit but untracked files present (use "git add" to track)
## * main
# git pull from remote server first
git pull
## Already up to date.

Let’s add what is inside README.md and add a new line to the end of the file

# new code chunk moves the working directory back
# If you know a cleaner way, please let me know.
cd ~/GitFolders/Math-7360-Xiang-Ji

head README.md

echo "Our course webpage is on [GitHub](https://tulane-math-7360-2023.github.io/) too!"$'\n' >> README.md

# take a look again
head README.md
## bash: line 2: cd: /Users/xji3/GitFolders/Math-7360-Xiang-Ji: No such file or directory
## head: README.md: No such file or directory
## Our course webpage is on [GitHub](https://tulane-math-7360-2023.github.io/) too!

Now let’s commit this change to the master branch

cd ~/GitFolders/Math-7360-Xiang-Ji

git status

# see the difference
git diff README.md

git add README.md

git commit -m 'add line about course webpage to readme'

git push
## bash: line 0: cd: /Users/xji3/GitFolders/Math-7360-Xiang-Ji: No such file or directory
## On branch main
## Your branch is up to date with 'origin/main'.
## 
## Untracked files:
##   (use "git add <file>..." to include in what will be committed)
##  ../../HW/HW1/HW1_Fall_2023.aux
##  ../../HW/HW1/HW1_Fall_2023.log
##  ../../HW/HW1/HW1_Fall_2023.synctex.gz
##  ../../HW/HW1/HW1_Fall_2023.tex
##  ../../HW/HW1/HW1_XJ.Rmd
##  ../../HW/HW1/HW1_XJ.html
##  ../../HW/HW1/HW1_keys.Rmd
##  ../../HW/HW1/HW1_keys.html
##  ../../HW/HW2/CRDT Data - CRDT.csv
##  ../../HW/HW2/HW2_keys.Rmd
##  ../../HW/HW2/HW2_keys.html
##  ../../HW/HW2/LA_COVID_AGE_GENDER_BYWEEK_PUBLICUSE.xlsx
##  ../../HW/HW2/LA_COVID_TESTBYDAY_PARISH_PUBLICUSE.xlsx
##  ../../HW/HW2/LA_COVID_TESTBYWEEK_TRACT_PUBLICUSE.xlsx
##  ../../HW/HW2/louisiana-history.csv
##  ../../HW/HW2/louisiana-race-ethnicity-historical.csv
##  ../../HW/HW2/old/
##  ../../HW/HW2/week.6.plot.jpg
##  ../../HW/HW2/week6.png
##  ../../HW/HW3/
##  ../../_layouts/Math7360_fall2023_logo.png
##  ./
## 
## nothing added to commit but untracked files present (use "git add" to track)
## [main 26a5e2e] add line about course webpage to readme
##  1 file changed, 2 insertions(+)
##  create mode 100644 lectures/lab-04-Git/README.md
## To https://github.com/tulane-math-7360-2023/tulane-math-7360-2023.github.io.git
##    523db83..26a5e2e  main -> main

And switch to develop branch, work on the same README.md file with different new line

$'\n' adds a line break

cd ~/GitFolders/Math-7360-Xiang-Ji

git checkout develop

git pull

git status

git branch

echo "This is our course [webpage](https://tulane-math-7360-2023.github.io/)!"$'\n' >> README.md

git diff README.md

git add README.md

git commit -m 'add a different line for course webpage to readme on develop'

git push
## bash: line 0: cd: /Users/xji3/GitFolders/Math-7360-Xiang-Ji: No such file or directory
## error: pathspec 'develop' did not match any file(s) known to git
## Already up to date.
## On branch main
## Your branch is up to date with 'origin/main'.
## 
## Untracked files:
##   (use "git add <file>..." to include in what will be committed)
##  ../../HW/HW1/HW1_Fall_2023.aux
##  ../../HW/HW1/HW1_Fall_2023.log
##  ../../HW/HW1/HW1_Fall_2023.synctex.gz
##  ../../HW/HW1/HW1_Fall_2023.tex
##  ../../HW/HW1/HW1_XJ.Rmd
##  ../../HW/HW1/HW1_XJ.html
##  ../../HW/HW1/HW1_keys.Rmd
##  ../../HW/HW1/HW1_keys.html
##  ../../HW/HW2/CRDT Data - CRDT.csv
##  ../../HW/HW2/HW2_keys.Rmd
##  ../../HW/HW2/HW2_keys.html
##  ../../HW/HW2/LA_COVID_AGE_GENDER_BYWEEK_PUBLICUSE.xlsx
##  ../../HW/HW2/LA_COVID_TESTBYDAY_PARISH_PUBLICUSE.xlsx
##  ../../HW/HW2/LA_COVID_TESTBYWEEK_TRACT_PUBLICUSE.xlsx
##  ../../HW/HW2/louisiana-history.csv
##  ../../HW/HW2/louisiana-race-ethnicity-historical.csv
##  ../../HW/HW2/old/
##  ../../HW/HW2/week.6.plot.jpg
##  ../../HW/HW2/week6.png
##  ../../HW/HW3/
##  ../../_layouts/Math7360_fall2023_logo.png
##  lab_04_git.Rmd
##  lab_04_git.html
##  lab_04_solutions.Rmd
##  lab_04_solutions.html
## 
## nothing added to commit but untracked files present (use "git add" to track)
## * main
## diff --git a/lectures/lab-04-Git/README.md b/lectures/lab-04-Git/README.md
## index 059d9b4..4463d20 100644
## --- a/lectures/lab-04-Git/README.md
## +++ b/lectures/lab-04-Git/README.md
## @@ -1,2 +1,4 @@
##  Our course webpage is on [GitHub](https://tulane-math-7360-2023.github.io/) too!
##  
## +This is our course [webpage](https://tulane-math-7360-2023.github.io/)!
## +
## [main 1ca4c24] add a different line for course webpage to readme on develop
##  1 file changed, 2 insertions(+)
## To https://github.com/tulane-math-7360-2023/tulane-math-7360-2023.github.io.git
##    26a5e2e..1ca4c24  main -> main

Now merge develop branch into master!

cd ~/GitFolders/Math-7360-Xiang-Ji

git checkout main
git pull
## bash: line 0: cd: /Users/xji3/GitFolders/Math-7360-Xiang-Ji: No such file or directory
## Already on 'main'
## Your branch is up to date with 'origin/main'.
## Already up to date.

This should create a conflict for you.

git merge develop

Please fix this merge conflict.