2022 DH Toolbox Intro To Git and GitHub
2022 DH Toolbox Intro To Git and GitHub
GitHub
Yoo Young Lee
2022.09.28
Fall 2022 DH Toolbox Series
Learning Outcomes
• You will be able to understand basic concepts of version
control system and Git.
• You will be able to perform basic Git commands.
• You will be able to work with remotes.
• You will be able to use GitHub Desktop.
Schedule
Time Topic
• Mostly used
• git status – git add – (git status) – git commit
Recap 1 - Exercise
• Exercise 6: Let’s modify the file, “hello.txt” and create
another file called, “DH2022.txt.”
• In the hello.txt: Add “Nice to meet you.”
• Create a file called, “DH2022.txt” with a line of “This is intro to
Git and GitHub at the 2022 Fall DH Toolbox Series.”
Recap 1 - Exercise
• Exercise 7: Let’s check git status.
• git status
Recap 1 - Exercise
• Exercise 8: Let’s add the modified file and new file to the
staging area.
• git add hello.txt
• git add DH2022.txt
• git status
Recap 1 - Exercise
• Exercise 9: Let’s commit them to the git repository with a
message.
• git commit –m “Added a new sentence in the hello.txt file
and created a new file, DH2022.txt”
git log
• git log: shows committed snapshots. It is a tool used for
examining a repository’s history and finding a particular
version of a project.
• Exercise 10: Let’s see a commit history in the repository.
• git log
git log
• git log: shows committed snapshots. It is a tool used for
examining a repository’s history and finding a particular
version of a project.
• Exercise 11: Let’s see what has changed.
• git log –p
• git log -2 || git log –n 2
• More git log cheatsheet
git log
Head and Master
• HEAD: the current commit your repository is on.
• Currently checked-out snapshot of your project.
• Master: the name of the default branch that git creates for you
when first creating a repository.
• In most cases, master means the main branch.
git show
• git show: used to view expanded details.
• Exercise 12: Let’s see what has changed in the specific
commit.
• git show commit_number
git diff
• git diff: shows changes between commits, commit and
working tree.
• Exercise 13: Let’s add a new sentence “Today is
Wednesday, September 28, 2022.” in the file, DH2022.txt.
• git diff
git diff
• git diff: shows changes between commits, commit and
working tree.
• Exercise 14: Let’s add it to staging and commit at the same
time as it is a small change.
• git status
• git commit –a –m “Added a date in the DH2022.txt file”
• git diff
Recap 2: Ger more information about changes
• git log
• git show
• git diff
git rm
• git rm: used to remove files from a Git repository. Tell git not
to track a file anymore.
• Exercise 15: Let’s not to track DH2022.txt file.
• git rm DH2022.txt
• git status
• git commit -m “Removed DH2022.txt from the git repository
as we don’t need it anymore”
git mv
• git mv: used to rename or move a file, a directory, or a
symlink
• Exercise 16: Let’s rename hello.txt to hi.txt.
• git mv hello.txt hi.txt
• git status
• git commit -m “Renamed hello.txt to hi.txt”
.gitignore
• .gitignore: indicates files which Git has been explicitly told
to ignore
• dependency caches
• compiled code
• files generated at runtime
• hidden system files
• Etc.
.gitignore
• Exercise 17: Let’s create .gititnore file and create a directory called
photos. Open .gititnore file in any text editor. Then, add
photos/ to tell Git to ignore anything in photos directory.
• touch .gitignore
• mkdir photos
• ls –la
• git status
• git add .gitignore
• git commit -m
“Added .gitignore
file.”
.gitignore
• Exercise 18: Let’s add a photo to photos/ and see how Git
behaves.
• git status
Recap 2: Delete and rename files
• git rm
• git mv
• .gititnore
git checkout
• git checkout: act of switching between different versions –
files, commits, and branches. Used to undo changes in the
working directory.
• Exercise 19: Let’s add more sentences in the hi.txt file. But
you realized that this is not what you wanted.
• git status
• git checkout hi.txt
• git status
git restore
• git restore: restores working tree files and helps to unstage
or even discard uncommitted local changes.
• Exercise 20: Let’s add more sentences in the hi.txt file and
add it to the staging area. Then, you realized that this is not
what you wanted.
• git status
• git add hi.txt
• git status
• git restore --staged hi.txt
• git status
• git restore hi.txt
• If you want to discard changes in working directory – similar to git checkout
file_name
git commit --amend
• git commit --amend: overwrites the previous commit and
allows you to modify and add changes to the most recent
commit. Avoid to use it if commits are already made public.
• Exercise 21: Let’s create a new file fall.txt file and add it to
the staging area and then commit.
• touch fall.txt
• git status
• git add fall.txt
• git commit -m “Added a new file called fall.txt”
git commit --amend
• git commit --amend: overwrites the previous commit and
allows you to modify and add changes to the most recent
commit. Avoid to use it if commits are already made public.
• Exercise 21: (Continued) Then you realized that you didn’t
add any content in the file. So add few sentences.
• git add fall.txt
• git commit --amend –m “Added a new file called fall.txt
with content”
git commit --amend
git commit --amend
git revert
• git revert: creates a new commit with inverse changes and
cancels previous changes instead of making it as though the
original commit never happened.
• Exercise 22: Let’s add more sentences to fall.txt. Then,
you don’t like the sentence that you just added it.
• git status
• git commit -a -m “Commit_message”
• git revert HEAD
• git log -2
git revert
Recap 3: Undo changes
• git checkout
• git restore
• git commit --ammend
• git revert
Branch