Git & GitHub track

Lesson 01 · Lessons

Getting Started

Installing Git, config, your first init and commit, and signing up for GitHub

Lessons6 min readFree lesson

Everyone has probably experienced the experience of files piling up like "last, last, last.zip" when modifying code without version control. Git is a tool that saves change history as a snapshot, allowing you to go back at any time. GitHub is a platform that puts this history on the Internet and allows multiple people to work together.

Learning Objectives

  • You can install Git and set user.name·user.email globally.
  • You can create a new repository with git init and leave the first commit.
  • You can check the storage status with git status·git log·git show.
  • Understand the flow of creating a GitHub account and creating a remote repository.

Why Git

Code continues to change over time. Because Git records “what changed, when, and why” on a per-commit basis. It becomes easier to undo mistakes or experiment with two ideas at the same time.


Key concepts

1) Install Git

Windows installation files

tools file name Description Official Download
Git for Windows Git-2.52.0-64-bit.exe Includes Git command line tools + Git Bash. You must install it to run git commands on Windows. git-scm.com/install/windows
TortoiseGit TortoiseGit-2.18.0.1-64bit.msi A GUI client that integrates Git functionality into Windows Explorer. You can manipulate commits, logs, and diffs with the mouse, which is useful when you are not familiar with the command line. Please use it after installing Git for Windows. tortoisegit.org/download

Installation order (Windows): Install in the following order: Git for Windows → TortoiseGit. TortoiseGit uses Git for Windows as its backend, so Git must be installed first.

macOS / Linux

# macOS
brew install git

# Ubuntu / Debian
sudo apt update && sudo apt install git

Check version after installation:

git --version
# git version 2.44.0

2) Global user settings

Sets author information that remains in all commits.

git config --global user.name  "Hong Gil-dong"
git config --global user.email "[email protected]"

#OK
git config --list --global
Options range
--global All repositories for current user
--local Current repository only (.git/config)
--system System wide

3) Repository initialization (git init)

mkdir my-project
cd my-project
git init
# Initialized empty Git repository in .../my-project/.git/

Once the .git/ folder is created, Git will start managing this directory.

4) First commit

Working directory → (git add) → staging area → (git commit) → repository
echo "# My Project" > README.md
git add README.md
git commit -m "docs: add README"

5) Three areas

area Description
Working Directory Where the actual files are
staging area A temporary space to store changes to commit
Repository (.git) Where commit snapshots are permanently stored

See as example

Example 1 — ex01_setup.sh: Check Git version and output user settings

#!/usr/bin/env bash
set -euo pipefail

echo "=== Check Git version ==="
git --version

echo ""
echo "=== Current global user settings ==="
git config --global user.name  || echo "(user.name not set)"
git config --global user.email || echo "(user.email not set)"

Execution result

=== Check Git version ===
git version 2.44.0

=== Current global user settings ===
Hong Gil-dong
[email protected]

Key point: You can look up the value saved as git config --global at any time.


Example 2 — ex02_init.sh: First commit after repository initialization in temporary directory

#!/usr/bin/env bash
set -euo pipefail

REPO=$(mktemp -d)
echo "Working directory: $REPO"
cd "$REPO"

git init
git config user.name  "For practice"
git config user.email "[email protected]"

echo "# Hello Git" > README.md
git add README.md
git commit -m "chore: initial commit"

echo ""
echo "=== Commit list ==="
git log --oneline

Execution result

Working directory: /tmp/tmp.XyZ123
Initialized empty Git repository in /tmp/tmp.XyZ123/.git/
[main (root-commit) a1b2c3d] chore: initial commit
 1 file changed, 1 insertion(+)
 create mode 100644 README.md

=== Commit list ===
a1b2c3d chore: initial commit

Key point: The three steps git init → git add → git commit are the basic cycle of Git.


Example 3 — ex03_status.sh: Observing working directory, staging, and commit status

#!/usr/bin/env bash
set -euo pipefail

REPO=$(mktemp -d)
cd "$REPO"
git init -q
git config user.name "For practice" && git config user.email "[email protected]"

echo "File 1" > a.txt
echo "[1] Status after adding files"
git status

git add a.txt
echo ""
echo "[2] Status after git add"
git status

git commit -q -m "add a.txt"
echo ""
echo "[3] Status after commit"
git status

Execution result

[1] Status after adding files
On branch main
Untracked files:
  a.txt

[2] Status after git add
On branch main
Changes to be committed:
  new file:   a.txt

[3] Status after commit
On branch main
nothing to commit, working tree clean

Bottom line: git status tells you which of the three areas a file is located in.


Example 4 — ex04_inspect.sh: Check commit log and contents

#!/usr/bin/env bash
set -euo pipefail

REPO=$(mktemp -d)
cd "$REPO"
git init -q
git config user.name "For practice" && git config user.email "[email protected]"

echo "first content" > file.txt
git add file.txt && git commit -q -m "feat: first file"

echo "add second line" >> file.txt
git add file.txt && git commit -q -m "feat: add second line"

echo "=== git log --oneline ==="
git log --oneline

echo ""
echo "=== git show HEAD ==="
git show HEAD

Execution result

=== git log --oneline ===
b2c3d4e feat: add second line
a1b2c3d feat: first file

=== git show HEAD ===
commit b2c3d4e...
Author: For practice <[email protected]>
Date:   ...

    feat: add second line

diff --git a/file.txt b/file.txt
...
+Add second line

Key point: git log shows a list of commits in reverse order, and git show HEAD shows a diff of the latest commit.


Seeing from a different perspective

Git concepts Everyday metaphor
storage photo album
commit One photo
staging area Print waiting tray
git add Upload photos to tray
git commit Paste in photo album

Common Mistakes

  1. git commit** without **git add — There is nothing in staging, so a “nothing to commit” error occurs.
  2. user.name/email not set — “Please tell me who you are” error occurs when committing.
  3. Run git init from your home directory — All files will be tracked and .git will become huge.
  4. Leave the commit message blank — If run without -m, the editor opens and the commit is canceled when saving with an empty message.
  5. Confusion between --global and --local — There may be a problem with commits being made from a company PC to a personal email.

Cleanup

  • Register the author as git config --global user.name/email.
  • git init → git add → git commit is the basic cycle.
  • Check the status of the three areas with git status and the commit history with git log.
  • You can view changes in a specific commit with git show <commit>.

Try it yourself

cd 01_Getting-started/src
chmod +x ex01_*.sh ex02_*.sh ex03_*.sh ex04_*.sh
./ex01_setup.sh
./ex02_init.sh
./ex03_status.sh
./ex04_inspect.sh

Application:

  1. Try changing the editor to git config --global core.editor "vim".
  2. Add the git log --oneline --graph --all option to print it in graph form.

Example files

The runnable files used in this lesson. Copy them into your own project and experiment.

src/ex01_setup.shShell
#!/usr/bin/env bash
set -euo pipefail

echo "=== Check Git version ==="
git --version

echo ""
echo "=== Current global user settings ==="
NAME=$(git config --global user.name 2>/dev/null || true)
EMAIL=$(git config --global user.email 2>/dev/null || true)

if [ -z "$NAME" ]; then
    echo "user.name: (not set)"
else
    echo "user.name: $NAME"
fi

if [ -z "$EMAIL" ]; then
    echo "user.email: (not set)"
else
    echo "user.email: $EMAIL"
fi

echo ""
echo "=== How to set up ==="
echo "git config --global user.name \"Hong Gil-dong\""
echo "  git config --global user.email \"[email protected]\""
src/ex02_init.shShell
#!/usr/bin/env bash
set -euo pipefail

REPO=$(mktemp -d)
echo "Working directory: $REPO"
cd "$REPO"

git init -b main
git config user.name  "For practice"
git config user.email "[email protected]"
    git config commit.gpgsign false

echo "# Hello Git" > README.md
git add README.md
git commit -m "chore: initial commit"

echo ""
echo "=== Commit list ==="
git log --oneline

echo ""
echo "=== .git internal structure ==="
ls .git/

#organizing
rm -rf "$REPO"
echo ""
echo "Temporary directory deletion complete"
src/ex03_status.shShell
#!/usr/bin/env bash
set -euo pipefail

REPO=$(mktemp -d)
cd "$REPO"
git init -q -b main
git config user.name  "For practice"
git config user.email "[email protected]"
    git config commit.gpgsign false

echo "File 1" > a.txt

echo "[1] Status (Untracked) after adding file"
git status

git add a.txt
echo ""
echo "[2] Status (Staged) after git add"
git status

git commit -q -m "add a.txt"
echo ""
echo "[3] Status after commit (Clean)"
git status

echo "What has been modified" >> a.txt
echo ""
echo "[4] Status after modifying the file (Modified)"
git status

rm -rf "$REPO"
src/ex04_inspect.shShell
#!/usr/bin/env bash
set -euo pipefail

REPO=$(mktemp -d)
cd "$REPO"
git init -q -b main
git config user.name  "For practice"
git config user.email "[email protected]"
    git config commit.gpgsign false

echo "first content" > file.txt
git add file.txt && git commit -q -m "feat: first file"

echo "add second line" >> file.txt
git add file.txt && git commit -q -m "feat: add second line"

echo "=== git log --oneline ==="
git log --oneline

echo ""
echo "=== git log --stat ==="
git log --stat --oneline

echo ""
echo "=== git show HEAD ==="
git show HEAD

echo ""
echo "=== git show HEAD~1 (previous commit) ==="
git show HEAD~1 --stat

rm -rf "$REPO"

Assignment

Problem 1

Save your name and email as Git global settings in the terminal, Write a script to check that the settings are saved correctly.

  • File name: hw01.sh
  • Requirements:
  • Set your name (or nickname) in git config --global user.name.
  • Set up email on git config --global user.email.
  • After setting, output the results as git config --list --global.
#Expected output (name and email are your own)
user.name=Hong Gil-dong
[email protected]

Problem 2

Create a new Git repository in a temporary directory, create the README.md file, and then Write a script that leaves the first commit and verifies it with git log.

  • File name: hw02.sh
  • Requirements:
  1. Create a temporary directory with mktemp -d.
  2. Initialize the storage with git init.
  3. Write # my first repository in README.md.
  4. Run git add README.md → git commit -m "docs: initial README".
  5. Check the commit with git log --oneline.
  6. Delete the temporary directory before ending the script.
#expected output
Initialized empty Git repository in /tmp/tmp.XXXXX/.git/
a1b2c3d docs: initial README

Check the correct answer

After writing it yourself, compare it with the reference solution below.

Show the reference solution

Try the assignment yourself first — comparing your attempt with a working solution is where most of the learning happens.

hw01.shShell
#!/usr/bin/env bash
set -euo pipefail

#Confirm after setting global user.name · user.email
git config --global user.name  "Hong Gil-dong"
git config --global user.email "[email protected]"

echo "=== Check global Git settings ==="
git config --list --global | grep -E "^user\."
hw02.shShell
#!/usr/bin/env bash
set -euo pipefail

REPO=$(mktemp -d)
echo "Repository location: $REPO"
cd "$REPO"

git init -b main
git config user.name  "Hong Gil-dong"
git config user.email "[email protected]"
    git config commit.gpgsign false

echo "# my first repository" > README.md
git add README.md
git commit -m "docs: initial README"

echo ""
echo "=== Commit Log ==="
git log --oneline

rm -rf "$REPO"
echo "Cleaned up"

Learn this lesson with a mentor

Work through the Git & GitHub track on your own, or join a guided cohort at our Pitampura campus and online.

Call NowEnroll Now