Git & GitHub

While Git is a local version control system, GitHub is a cloud-based platform for hosting Git repositories.

  • README.md

  • .gitignore

  • .gitattributes

  • .git/hooks

  • .github/workflows/*.yml

  • git version

  • git config list --show-origin

    Lists system, global, and local configurations and their origin.

  • git config --global user.name <name>

  • git config --global user.email <email>

  • git clone <url>

  • git ls-files

    Lists tracked files.

    • git ls-files --eol

      Lists tracked files with end-of-line information.

    • git ls-files --others (-o) --exclude-standard

      Lists untracked files excluding ignored files.


  • git init

  • git status

  • git stash

    Cuts the changes in the current project and pastes them into the stash archive.

    • git stash push <file-name>

      Cuts the changes in the specified file and pastes them into the stash archive.

    • git stash list

      Lists stashes.

    • git stash show

      Shows the changes in the latest stash.

    • git stash pop

      Cuts the latest stash in the stash archive and pastes it into the current project.

    • git stash apply

      Copies the latest stash in the stash archive into the current project.

    • git stash drop

      Deletes the latest stash in the stash archive.

  • git add .

    Stages changes.

  • git commit

    Creates a commit with staged changes.

    One task per commit. Avoid combining multiple tasks into a single commit.

    Text
    <type>(optional scope): <summary>
    
    <description>

    <type> can be feat, fix, refactor, chore, style, docs, test, build, content, crawl, etc.

    <summary> should use the imperative mood, start with a lowercase letter, omit articles, and not end with a period.

    A blank line is recommended between <summary> and <description>.

    • git commit --message (-m) <summary> --message (-m) <description>

    • git commit --amend

      Adds staged changes to the latest commit and updates its message.

  • git revert <commit-id>

    Creates a commit that undoes the changes of the specified commit.

  • git reset <commit-id>

    Deletes commits after the specified commit, keeps the changes unstaged, and preserves the specified commit. This has the implicit --mixed flag, which is the default.

    • git reset --soft <commit-id>

      Deletes commits after the specified commit, keeps the changes staged, and preserves the specified commit.

    • git reset --hard <commit-id>

      Deletes commits after the specified commit, also deletes the changes, and preserves the specified commit.

  • git log

    Lists the commit history.

    • git log -S <string>

      Finds commits where the specified string was added or removed.

  • git show

    Shows the latest commit with its diff.


  • git branch

    Lists local branches.

    • git branch --verbose (-v)

      Lists local branches verbosely.

    • git branch --verbose --verbose (-vv)

      Lists local branches more verbosely.

    • git branch --all (-a)

      Lists local branches and remote repository branches.

    • git branch <branch-name>

      Creates the specified branch.

    • git branch --delete (-d) <branch-name>

      Deletes the specified branch.

    • git branch --move (-m) <specified-branch-name> <new-branch-name>

      Renames the specified branch.

  • git checkout

    Shows a brief status of the current branch.

    • git checkout <branch-name>, git switch <branch-name>

      Moves from the current branch to the specified branch.

      Uncommited changes are carried over to the specified branch if there is no conflict.

    • git checkout -, git switch -

      Moves to the previous branch or commit.

    • git checkout -b <branch-name>, git switch --create (-c) <branch-name>

      Creates the specified branch and moves to it.

    • git checkout <commit-id>, git switch --detach <commit-id>

      Moves HEAD directly to the specified commit without being attached to any branch.

    • git checkout -- <file-name>, git restore <file-name>

      Restores the specified file to the last commit state.

  • git merge <branch-name>

    Merges the specified branch into the current branch.

    • git merge --abort

    • git merge --continue

  • git rebase <branch-name>

    Cuts the commits of the current branch that diverge from the specified branch and pastes them onto the specified branch to create a linear history. After rebasing, the specified branch should be fast-forward merged.

    • git rebase --interactive (-i) HEAD~<number>

      Goes back to the specified number of commits and modifies them interactively (pick, edit, squash, fixup, reword, drop, etc.).

    • git rebase --abort

    • git rebase --continue


  • git remote

    Lists remote repository aliases.

    • git remote --verbose (-v)

      Lists remote repository aliases and their URLs.

    • git remote add <remote-repository-alias> <remote-repository-url>

      Creates the alias for the remote repository and connects the current project to it.

    • git remote remove (rm) <remote-repository-alias>

      Disconnects the current project from the specified remote repository.

    • git remote set-url <remote-repository-alias> <remote-repository-url>

      Updates the URL of the specified remote repository.

  • git push <remote-repository-alias> <branch-name>

    Uploads the local branch to the remote repository branch that has the same name as the local branch. If the local and remote names are different, <branch-name> will be <local-branch-name>:<remote-repository-branch-name>

    • git push --set-upstream (-u) <remote-repository-alias> <branch-name>

      Uploads and remembers this connection. Thereafter, you can simply run git push, git fetch, or git pull without arguments.

  • git fetch <remote-repository-alias> <remote-branch-name>

    Downloads the changes from the specified remote repository branch without merging them.

  • git pull <remote-repository-alias> <remote-branch-name>

    Downloads the changes from the specified remote repository branch and merges them into the current branch.

Git Hooks are located in .git/hooks and must not have a file extension.

Git Hooks are custom scripts that trigger actions when a specified event occurs. They are divided into client-side hooks and server-side hooks.

  • commit-msg

    The following code creates a custom Windows modal dialog that checks if the message summary to commit contains the content type, prompting the user to confirm whether the lastUpdated prop was updated.

    Bash | commit-msg
    #!/bin/sh
    
    SUMMARY=$(head -n 1 "$1")
    
    if echo "$SUMMARY" | grep -iq "^content"; then
        USER_CHOICE=$(powershell.exe -NoProfile -ExecutionPolicy Bypass -Command '
            # Play the notification sound.
            [System.Media.SystemSounds]::Asterisk.Play()
    
            # Load the required assemblies.
            [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
            [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null
    
            # Create the window form.
            $form = New-Object System.Windows.Forms.Form
            $form.Text = "⚠️ Git Hook commit-msg"
            $form.Size = New-Object System.Drawing.Size(550, 260)
            $form.StartPosition = "CenterScreen"
            $form.FormBorderStyle = "FixedDialog"
            $form.MaximizeBox = $false
            $form.MinimizeBox = $false
            $form.TopMost = $true
    
            # Create the message label.
            $label = New-Object System.Windows.Forms.Label
            $label.Text = "The [content] type has been detected!`n`nDid you update the [lastUpdated] variable?"
            $label.Location = New-Object System.Drawing.Point(30, 30)
            $label.Size = New-Object System.Drawing.Size(490, 100)
            $label.Font = New-Object System.Drawing.Font("Malgun Gothic", 14, [System.Drawing.FontStyle]::Bold)
    
            # Create the "Yes" button.
            $btnYes = New-Object System.Windows.Forms.Button
            $btnYes.Text = "Yes"
            $btnYes.DialogResult = [System.Windows.Forms.DialogResult]::Yes
            $btnYes.Location = New-Object System.Drawing.Point(140, 150)
            $btnYes.Size = New-Object System.Drawing.Size(120, 45)
            $btnYes.Font = New-Object System.Drawing.Font("Malgun Gothic", 11)
    
            # Create the "No" button.
            $btnNo = New-Object System.Windows.Forms.Button
            $btnNo.Text = "No"
            $btnNo.DialogResult = [System.Windows.Forms.DialogResult]::No
            $btnNo.Location = New-Object System.Drawing.Point(280, 150)
            $btnNo.Size = New-Object System.Drawing.Size(120, 45)
            $btnNo.Font = New-Object System.Drawing.Font("Malgun Gothic", 11)
    
            # Set the keyboard shortcuts (Enter -> "Yes", Esc -> "No").
            $form.AcceptButton = $btnYes
            $form.CancelButton = $btnNo
    
            # Add the created components to the window form.
            $form.Controls.Add($label)
            $form.Controls.Add($btnYes)
            $form.Controls.Add($btnNo)
    
            # Open the window.
            $result = $form.ShowDialog()
    
            # Return result to USER_CHOICE.
            Write-Output $result
        ' | tr -d '\r')
    
        # Cancel the current message if the user selects anything other than "Yes"
        if [ "$USER_CHOICE" != "Yes" ]; then
            powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "[System.Media.SystemSounds]::Hand.Play()"
            echo "❌ The commit was canceled. Please update the [lastUpdated] variable."
    
            exit 1
        fi
    fi
    
    exit 0
  • pre-push

    The following code creates a custom Windows modal dialog that checks if the commit message summaries to push contain the content type, prompting the user to confirm whether the search/pages folder was updated.

    Bash | pre-push
    #!/bin/sh
    
    SUMMARIES=$(git log @{u}..HEAD --pretty=format:"%s" 2>/dev/null)
    
    if [ -z "$SUMMARIES" ]; then
        SUMMARIES=$(git log -n 5 --pretty=format:"%s")
    fi
    
    if echo "$SUMMARIES" | grep -iq "^content"; then
        USER_CHOICE=$(powershell.exe -NoProfile -ExecutionPolicy Bypass -Command '
            # Play the notification sound.
            [System.Media.SystemSounds]::Asterisk.Play()
    
            # Load the required assemblies.
            [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
            [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null
    
            # Create the window form.
            $form = New-Object System.Windows.Forms.Form
            $form.Text = "⚠️ Git Hook pre-push"
            $form.Size = New-Object System.Drawing.Size(550, 260)
            $form.StartPosition = "CenterScreen"
            $form.FormBorderStyle = "FixedDialog"
            $form.MaximizeBox = $false
            $form.MinimizeBox = $false
            $form.TopMost = $true
    
            # Create the message label.
            $label = New-Object System.Windows.Forms.Label
            $label.Text = "The [content] type has been detected!`n`nDid you do [npm run dev-content-change]?"
            $label.Location = New-Object System.Drawing.Point(30, 30)
            $label.Size = New-Object System.Drawing.Size(490, 100)
            $label.Font = New-Object System.Drawing.Font("Malgun Gothic", 14, [System.Drawing.FontStyle]::Bold)
    
            # Create the "Yes" button.
            $btnYes = New-Object System.Windows.Forms.Button
            $btnYes.Text = "Yes"
            $btnYes.DialogResult = [System.Windows.Forms.DialogResult]::Yes
            $btnYes.Location = New-Object System.Drawing.Point(140, 150)
            $btnYes.Size = New-Object System.Drawing.Size(120, 45)
            $btnYes.Font = New-Object System.Drawing.Font("Malgun Gothic", 11)
    
            # Create the "No" button.
            $btnNo = New-Object System.Windows.Forms.Button
            $btnNo.Text = "No"
            $btnNo.DialogResult = [System.Windows.Forms.DialogResult]::No
            $btnNo.Location = New-Object System.Drawing.Point(280, 150)
            $btnNo.Size = New-Object System.Drawing.Size(120, 45)
            $btnNo.Font = New-Object System.Drawing.Font("Malgun Gothic", 11)
    
            # Set the keyboard shortcuts (Enter -> "Yes", Esc -> "No").
            $form.AcceptButton = $btnYes
            $form.CancelButton = $btnNo
    
            # Add the created components to the window form.
            $form.Controls.Add($label)
            $form.Controls.Add($btnYes)
            $form.Controls.Add($btnNo)
    
            # Open the window.
            $result = $form.ShowDialog()
    
            # Return result to USER_CHOICE.
            Write-Output $result
        ' | tr -d '\r')
    
        # Cancel the current push if the user selects anything other than "Yes"
        if [ "$USER_CHOICE" != "Yes" ]; then
            powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "[System.Media.SystemSounds]::Hand.Play()"
            echo "❌ The push was canceled. Please do [npm run dev-content-change]."
    
            exit 1
        fi
    fi
    
    exit 0

GitHub Actions is a continuous integration and continuous deployment (CI/CD) service.

GitHub Actions provides secrets, variables, artifacts, and outputs.

GitHub Actions consists of workflows that are located in .github/workflows with .yml. Workflows are triggered by specific events and contain one or more jobs.

Jobs run on a runner and contain one or more steps. Jobs run in parallel by default but can run sequentially by specifying needs.

Steps execute a shell command, a custom action, or a third-party action. Steps run in order.

  • Korean comments are garbled in GitHub.

  • The connection between a local repository and GitHub is lost.