DevOps.Academy
CoursesCurriculumInterview prepPricing
◔My learningSign in
DevOps.Academy

Free, hands-on DevOps lessons. Made with care in India.

System status

Learn

All coursesLinux roadmapCurriculumInterview questionsCheat sheetsMy learning

Academy

PricingCertificates

Legal

PrivacyTermsContact

devops.rajeev.pro

Git & GitHub · revision

Git & GitHub cheat sheet

Recall first: read each stage's one-line summary and try to remember its commands. Then open the stage to check yourself.

13 stages26 commands

01The basicsGit records snapshots of a project so you can see and share how it changed. Set your author identity once, then start each repository with a deliberate initial branch and clean status.
  • git --version

    Confirm that Git is installed

  • git config --global user.name "Your Name"

    Set the author name used for commits

Remember

  • user.name and user.email become commit metadata.
  • Global config is the default; repository config can override it for one project.

Watch for A commit records the configured identity, not an account you logged into on GitHub.

Open the lesson: Version control, and setting Git up once →
02RepositoriesA change moves from the working tree to the staging area and then into a commit. Inspect the staged snapshot before saving it, and keep generated or secret files out with .gitignore.
  • git status --short

    See staged and unstaged changes in compact form

  • git add README.md

    Stage one file for the next commit

Remember

  • The index is the snapshot that the next commit will record.
  • A commit message should explain the change, not just say that something was updated.

Watch for git add stages file contents; edit the file again and it can have unstaged changes too.

Open the lesson: Commits: the working folder, the staging area and history →
03BranchingA branch is a movable pointer to a commit. Create one for isolated work, switch between branches intentionally, and merge a finished change back into the shared line.
  • git switch -c feature/coupons

    Create a branch and switch to it

  • git branch

    List local branches and mark the current branch

Remember

  • Creating a branch does not copy the working tree; it names a commit.
  • Uncommitted changes can follow you when switching if Git can apply them safely.

Watch for Check git status before switching; uncommitted edits may prevent the switch or move with you.

Open the lesson: Branches: work on many things without breaking main →
04GitHub essentialsGitHub hosts repositories and the team workflow around them. Keep your account identity private where needed, and distinguish cloning an existing project from forking one to propose work.
  • gh auth status

    Check which GitHub account and authentication method the CLI is using

  • gh auth login

    Start the GitHub CLI login flow

Remember

  • A clone is your local copy; a fork is a separate GitHub repository under your account.
  • GitHub's noreply email can keep a personal email out of public commit metadata.

Watch for Authentication with gh does not change the author identity already configured in Git.

Open the lesson: GitHub: your account, repositories, forks and clones →
05RemotesRemotes name other repositories, while remote-tracking branches record the last fetched state. Fetch first when you need to inspect incoming work before integrating it.
  • git remote -v

    List remote names and their fetch/push URLs

  • git remote add upstream https://github.com/owner/shop.git

    Add a second remote, such as the source repository for a fork

Remember

  • fetch updates remote-tracking refs without changing your current branch.
  • A rejected push often means the remote has commits you have not integrated yet.

Watch for git pull integrates fetched changes; use git fetch when you want to inspect first.

Open the lesson: Remotes: push, fetch and pull without surprises →
06Merge strategiesMerge, fast-forward, rebase and squash create different histories. Choose the team's expected history, resolve conflicts with both sides understood, and use cherry-pick for one commit.
  • git log --oneline --graph --all

    Visualize commits and branch relationships

  • git merge --ff-only feature/x

    Merge only if the current branch can move forward without a merge commit

Remember

  • A merge commit preserves the joined history; a fast-forward only advances a branch pointer.
  • Rebase rewrites commit IDs because it replays commits on a new base.

Watch for Don't rebase commits that other people already depend on unless the team has agreed on it.

Open the lesson: Merge, rebase, squash: combining work, and fixing conflicts →
07CollaborationTeams coordinate work with issues and pull requests, review changes before merging, and protect the main branch with required checks. Forks let contributors propose work without direct write access.
  • git switch -c fix/42-empty-cart

    Start a focused branch for an issue

  • gh issue list --label bug --assignee @me

    Find assigned bug issues with the GitHub CLI

Remember

  • A pull request is a review and integration proposal, not merely a way to upload a branch.
  • Branch protection makes review and passing checks enforceable before merge.

Watch for Passing local tests alone does not satisfy required checks configured on the remote.

Open the lesson: Collaboration: issues, pull requests and code review →
08Undoing changesPick an undo operation based on where the change lives: restore a file, unstage it, reset a private local commit, revert a shared commit, or stash work you need to set aside.
  • git revert --no-edit HEAD

    Create a new commit that reverses the current commit

  • git log --oneline -2

    Verify the latest history after an undo

Remember

  • revert preserves shared history by adding an inverse commit.
  • reflog can help recover a recent commit reference after a local pointer move.

Watch for reset moves a branch pointer; avoid using it to rewrite commits already shared with others.

Open the lesson: Undoing changes: revert, reset, stash and reflog →
09History & diffsUse history filters to find the relevant commit, then compare the right two states with a diff. Blame and bisect narrow a problem to a line or to the commit that introduced it.
  • git log --oneline --since="2 weeks ago"

    Filter commit history by date

  • git switch --detach HEAD~3

    Inspect an earlier commit without switching to a branch

Remember

  • Detached HEAD is useful for inspection; new commits there are not on a named branch.
  • git bisect narrows a regression by repeatedly testing a known-good and bad range.

Watch for If you commit in detached HEAD, create a branch before switching away so the commit stays reachable.

Open the lesson: History and diffs: find what changed, who changed it, and when it broke →
10Rewriting historyClean up a private branch with amend, interactive rebase and fixup commits before review. Once others may have based work on it, coordinate before rewriting its published history.
  • git commit --amend --no-edit

    Add staged changes to the previous commit without changing its message

  • git log --oneline main..

    Review commits on the current branch that are not on main

Remember

  • Amend and rebase replace commit IDs.
  • A force-with-lease push checks the remote ref before replacing it, but still rewrites shared history.

Watch for Never force-push over someone else's work; inspect and coordinate before updating a rewritten branch.

Open the lesson: Rewriting history: amend, interactive rebase and safe force-pushes →
11Tags & releasesMark a specific commit with a version tag, use semantic versioning to communicate change size, and publish release notes that describe what shipped.
  • git tag -a v1.0.0 -m "First stable release"

    Create an annotated version tag on the current commit

  • git show v1.0.0

    Inspect the tagged commit and its annotation

Remember

  • An annotated tag is a Git object with metadata; a lightweight tag is only a name.
  • Semantic versions use major, minor and patch numbers to signal compatibility changes.

Watch for A local tag is not on GitHub until you push it.

Open the lesson: Tags and releases: version numbers people can trust →
12Hooks & automationHooks run local checks at Git events, and tracked hook directories make setup repeatable. Add repository automation only after you know what it checks and where it runs.
  • git config core.hooksPath .githooks

    Point this repository at its tracked hook directory

  • chmod +x .githooks/*

    Make the tracked hook scripts executable

Remember

  • A local hook can be bypassed or absent on another machine; remote checks enforce shared rules.
  • Hooks should fail clearly and quickly when they block a commit.

Watch for A hook that exists in Git but is not executable will not run as expected.

Open the lesson: Hooks and automation: let Git check your work →
13Security & extrasKeep credentials out of commits, respond quickly if one leaks, and use signing and dependency tools to improve trust. LFS and submodules solve different repository-size and composition needs.
  • git config --global gpg.format ssh

    Configure Git to use SSH keys for commit signing

  • git config --global commit.gpgsign true

    Sign commits by default

Remember

  • Removing a secret from the latest file does not remove it from earlier commits.
  • Rotate or revoke a leaked credential before cleaning history.

Watch for History cleanup cannot make an exposed credential safe again; revoke it first.

Open the lesson: Security and extras: secrets, Dependabot, LFS, submodules and Pages →
← Back to the Git & GitHub course