Excercise 1 - Module 1 - Simple Commit | |
# 0. Clone from github | |
$ git clone http://github.com/stephenh/git-workshop.git | |
$ cd git-workshop | |
# 1. Tell git who you are (once per machine) | |
$ git config --global user.name "Your Name" | |
$ git config --global user.email your.email@example.com | |
$ git config --global color.ui auto | |
# 2. Make a new file | |
$ echo "line1" > new.txt | |
# 3. See your status, new.txt is untracked | |
$ git status | |
# 4. Stage the new file | |
$ git add new.txt | |
# 5. git status, new.txt is "to be committed" | |
$ git status | |
# Think of "svn commit file1 file2", in git this | |
# is "add file1", "add file2", "commit". Staging, | |
# then committing. | |
# 6. commit | |
$ git commit -m "Added new.txt." | |
# 7. See the history | |
$ git log | |
# 8. Add a nice alias for log (no newlines) | |
$ git config --global alias.l "log | |
--graph | |
--pretty=oneline | |
--abbrev-commit | |
--decorate" | |
$ git l | |
Excercise 1 - Module 2 - Diff, Undo Line Changes | |
# 1. Add a line to new.txt, see the status | |
$ echo "line2" >> new.txt | |
$ git status | |
# 2. See the change | |
$ git diff | |
# 3. Undo your change, line2 is removed, nothing to commit | |
$ git checkout new.txt | |
$ git status | |
# 4. Re-add line 2 and now stage the change | |
$ echo "line2" >> new.txt | |
$ git add new.txt | |
# 5. See the staged change | |
$ git diff --staged | |
# 6. Note regular diff does not show changes | |
$ git diff | |
# diff == working <-> staged | |
# diff --staged == staged <-> HEAD | |
# 7. Unstage the change, new.txt is back to modified | |
$ git reset new.txt | |
$ git status | |
# 8. Undo the change, line2 is removed, nothing to commit | |
$ git checkout new.txt | |
$ git status | |
Excercise 1 - Module 3 - Diff, Undo File Changes | |
code> | |
# 1. Add, stage a new file, see it staged | |
$ echo "line1" > new-b.txt | |
$ git add new-b.txt | |
$ git status | |
# 2. Unstage the new file, new-b.txt is back to untracked | |
$ git reset new-b.txt | |
$ git status | |
$ rm new-b.txt | |
# 3. Remove new.txt, it is shown as deleted | |
$ rm new.txt | |
$ git status | |
# 4. Stage the removal, it is shown as "to be committed" | |
$ git rm new.txt | |
$ git status | |
# 5. Unstage the removal (HEAD is important, try without it) | |
$ git reset HEAD new.txt | |
$ git status | |
# 6. Restore new.txt in working copy | |
$ git checkout new.txt | |
$ git status |
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND