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 master

# list files
ls -lt

# check git status
git status

# check branch
git branch
## Already on 'master'
## Your branch is up to date with 'origin/master'.
## total 8
## -rw-r--r--  1 xji3  staff  154 Sep 16 16:00 README.md
## drwxr-xr-x  5 xji3  staff  160 Sep 16 16:00 HW1
## On branch master
## Your branch is up to date with 'origin/master'.
## 
## nothing to commit, working tree clean
##   develop
## * master
# 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-math7360.github.io/) too!"$'\n' >> README.md

# take a look again
head README.md
## # Math-7360-Xiang-Ji
## The repository that stores all course-related materials.
## Our course webpage is on [GitHub](https://tulane-math7360.github.io/) too!
## 
## # Math-7360-Xiang-Ji
## The repository that stores all course-related materials.
## Our course webpage is on [GitHub](https://tulane-math7360.github.io/) too!
## 
## Our course webpage is on [GitHub](https://tulane-math7360.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 master
## Your branch is up to date with 'origin/master'.
## 
## Changes not staged for commit:
##   (use "git add <file>..." to update what will be committed)
##   (use "git checkout -- <file>..." to discard changes in working directory)
## 
##  modified:   README.md
## 
## no changes added to commit (use "git add" and/or "git commit -a")
## diff --git a/README.md b/README.md
## index 5beeb98..b584587 100644
## --- a/README.md
## +++ b/README.md
## @@ -2,3 +2,5 @@
##  The repository that stores all course-related materials.
##  Our course webpage is on [GitHub](https://tulane-math7360.github.io/) too!
##  
## +Our course webpage is on [GitHub](https://tulane-math7360.github.io/) too!
## +
## [master 3026242] add line about course webpage to readme
##  1 file changed, 2 insertions(+)
## To https://github.com/tulane-math7360/Math-7360-Xiang-Ji.git
##    b8b448e..3026242  master -> master

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-math7360.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'.
## 
## nothing to commit, working tree clean
## * develop
##   master
## diff --git a/README.md b/README.md
## index f726fb3..713ab43 100644
## --- a/README.md
## +++ b/README.md
## @@ -3,3 +3,5 @@ The repository that stores all course-related materials.
##  
##  This is our course [webpage](https://tulane-math7360.github.io/)!
##  
## +This is our course [webpage](https://tulane-math7360.github.io/)!
## +
## [develop c90cbbc] add a different line for course webpage to readme on develop
##  1 file changed, 2 insertions(+)
## To https://github.com/tulane-math7360/Math-7360-Xiang-Ji.git
##    95522c5..c90cbbc  develop -> develop

Now merge develop branch into master!

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

git checkout master
git pull
## Switched to branch 'master'
## Your branch is up to date with 'origin/master'.
## Already up to date.

This should create a conflict for you.

git merge develop

Please fix this merge conflict.