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
## Already on 'main'
## Your branch is up to date with 'origin/main'.
## total 8
## -rw-r--r--  1 xji3  staff  222 Oct  7 22:02 README.md
## 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)
##  .DS_Store
## 
## nothing added to commit but untracked files present (use "git add" to track)
##   develop
## * 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-2021.github.io/) too!"$'\n' >> README.md

# take a look again
head README.md
## # Math-7360-Xiang-Ji
## Math 7360 HW and Lab submission repo
## Our course webpage is on [GitHub](https://tulane-math-7360-2021.github.io/) too!
## 
## Our course webpage is on [GitHub](https://tulane-math-7360-2021.github.io/) too!
## 
## # Math-7360-Xiang-Ji
## Math 7360 HW and Lab submission repo
## Our course webpage is on [GitHub](https://tulane-math-7360-2021.github.io/) too!
## 
## Our course webpage is on [GitHub](https://tulane-math-7360-2021.github.io/) too!
## 
## Our course webpage is on [GitHub](https://tulane-math-7360-2021.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
## On branch main
## Your branch is up to date with 'origin/main'.
## 
## Changes not staged for commit:
##   (use "git add <file>..." to update what will be committed)
##   (use "git restore <file>..." to discard changes in working directory)
##  modified:   README.md
## 
## Untracked files:
##   (use "git add <file>..." to include in what will be committed)
##  .DS_Store
## 
## no changes added to commit (use "git add" and/or "git commit -a")
## diff --git a/README.md b/README.md
## index 3527889..517d0b6 100644
## --- a/README.md
## +++ b/README.md
## @@ -4,3 +4,5 @@ Our course webpage is on [GitHub](https://tulane-math-7360-2021.github.io/) too!
##  
##  Our course webpage is on [GitHub](https://tulane-math-7360-2021.github.io/) too!
##  
## +Our course webpage is on [GitHub](https://tulane-math-7360-2021.github.io/) too!
## +
## [main 8369980] add line about course webpage to readme
##  1 file changed, 2 insertions(+)
## To https://github.com/tulane-math-7360-2021/Math-7360-Xiang-Ji.git
##    0fb0352..8369980  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-2021.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
## Switched to branch 'develop'
## Your branch is up to date with 'origin/develop'.
## Already up to date.
## On branch develop
## Your branch is up to date with 'origin/develop'.
## 
## Untracked files:
##   (use "git add <file>..." to include in what will be committed)
##  .DS_Store
## 
## nothing added to commit but untracked files present (use "git add" to track)
## * develop
##   main
## diff --git a/README.md b/README.md
## index 383caa6..2d8b0fb 100644
## --- a/README.md
## +++ b/README.md
## @@ -12,3 +12,5 @@ This is our course [webpage](https://tulane-math-7360-2021.github.io/!
##  
##  This is our course [webpage](https://tulane-math-7360-2021.github.io/!
##  
## +This is our course [webpage](https://tulane-math-7360-2021.github.io/)!
## +
## [develop 7167949] add a different line for course webpage to readme on develop
##  1 file changed, 2 insertions(+)
## To https://github.com/tulane-math-7360-2021/Math-7360-Xiang-Ji.git
##    87cb216..7167949  develop -> develop

Now merge develop branch into master!

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

git checkout main
git pull
## Switched to branch '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.