Git & GitHub #

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

Files & Folders #

  • Git
    • README.md
    • .gitignore
    • .gitattributes
  • GitHub Actions
    • .github/workflows
      • *.yml

Git Command Lines #

  • 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 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 all 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 all changes.

  • git commit

    Creates a commit with all staged changes.

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

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

      In IDEs, a blank line is required between the summary and the description.

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

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

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

  • git revert <commit-id>

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

  • git reset <commit-id>

    Deletes all 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 all commits after the specified commit, keeps the changes staged, and preserves the specified commit.

    • git reset --hard <commit-id>

      Deletes all 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 all local branches.

    • git branch --verbose (-v)

      Lists all local branches verbosely.

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

      Lists all local branches more verbosely.

    • git branch --all (-a)

      Lists all 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 the 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

      Aborts the paused merge process due to conflicts and restores the current branch to its pre-merge state.

    • git merge --continue

      Resumes the paused merge process after resolving conflicts and staging the resolved changes.

  • 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 --abort

      Aborts the paused rebase process due to conflicts and restores the current branch to its pre-rebase state.

    • git rebase --continue

      Resumes the paused rebase process after resolving conflicts and staging the resolved changes.


  • git remote

    Lists all remote repository aliases.

    • git remote --verbose (-v)

      Lists all 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.

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. Workflows are triggered by events and have one or more jobs.

Jobs run on a runner and have 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.

Errors #

  • Korean comments are broken in GitHub.
  • The connection between a local repository and GitHub is broken.