Git Commands Flashcards: Everyday Workflow, Branching & Recovery

Practice essential Git commands with safe, current examples for staging, commits, branches, remotes, history, undoing changes, and recovery.

За това тесте

Git commands are easier to remember when the prompt starts with a real situation: inspect a change, stage part of a file, move work onto a branch, update from a remote, or recover a commit that seemed lost.

What this deck practices

  • Situation → command: choose a practical Git command or safe command sequence for the state in front of you.
  • Command → effect: explain what a command reads or changes, including the working tree, index, branch, remote-tracking refs, or commit history.
  • Risk → safer choice: distinguish local cleanup from shared-history changes, and recognize when restore, revert, reset, reflog, or a force push needs extra care.
  • Output → next step: read common status, diff, log, bisect, stash, branch, tag, and worktree results well enough to continue.

The sequence starts with repository setup and observation, moves through staging and commits, then adds branches, remotes, integration, history, debugging, undo, and recovery. Related prompt directions are separated so the neighboring card doesn't give away the answer.

This deck covers 36 useful top-level commands with modern porcelain such as git switch and git restore. Common older git checkout and git reset <path> forms appear only as compatibility notes. It excludes hosting-service pull requests, GUIs, credentials, server administration, most low-level plumbing commands, hooks, signing, Git LFS, submodules, partial clones, custom aliases, and exhaustive option catalogs. The practical low-level exceptions are git ls-files, git merge-base, and git rev-parse, which support everyday inspection and comparison tasks.

CC0 applies to the independently authored questions, answers, organization, metadata, and generated cover only to the extent applicable rights exist; it doesn't license Git facts, documentation, names, or trademarks.

Facts and examples were checked against the current official Git documentation and executed in disposable repositories with Git 2.50.1. This is an independent, unofficial educational deck. It isn't affiliated with or endorsed by the Git Project or Software Freedom Conservancy. No documentation prose, logos, command tables, competitor cards, or assessment questions were copied.

Карти в това тесте

  1. Карта 1

    Въпрос

    Initialize the current directory as a Git repository.

    Отговор

    git init creates the repository metadata in the current directory.

    git init
    

    It doesn't add or commit the existing files.

  2. Карта 2

    Въпрос

    Set the commit email for only the current repository.

    Отговор

    git config user.email dev@example.com sets a repository-local value.

    git config user.email dev@example.com
    

    Omitting --global keeps other repositories unchanged.

  3. Карта 3

    Въпрос

    Open the full manual for git status.

    Отговор

    git help status opens the command's manual.

    git help status
    

    Use git status -h when you only need the short option summary in the terminal.

  4. Карта 4

    Въпрос

    Copy ../origin.git into a new local directory named project.

    Отговор

    git clone ../origin.git project creates the local clone in project.

    git clone ../origin.git project
    

    The clone normally configures the source as the origin remote.

  5. Карта 5

    Въпрос

    Show tracked changes that haven't been staged.

    Отговор

    git diff shows the working-tree changes relative to the index.

    git diff
    

    New untracked files don't appear until Git knows about them.

  6. Карта 6

    Въпрос

    Stage notes.txt for the next commit.

    Отговор

    git add notes.txt copies the path's current content into the index.

    git add notes.txt
    

    Later edits to the file stay unstaged until you add them too.

  7. Карта 7

    Въпрос

    Inspect which changes are staged, unstaged, or untracked.

    Отговор

    git status compares the working tree and index with HEAD.

    git status
    

    It reads repository state; it doesn't modify files or history.

  8. Карта 8

    Въпрос

    Record the staged snapshot with the message Add notes.

    Отговор

    git commit -m "Add notes" creates a commit from the index.

    git commit -m "Add notes"
    

    Unstaged changes aren't included.

  9. Карта 9

    Въпрос

    Delete the tracked file obsolete.txt and stage that deletion.

    Отговор

    git rm obsolete.txt removes the file and stages the removal.

    git rm obsolete.txt
    

    Commit afterward to record the deletion in history.

  10. Карта 10

    Въпрос

    Rename tracked old-name.txt to notes.txt and stage the change.

    Отговор

    git mv old-name.txt notes.txt moves the path and updates the index.

    git mv old-name.txt notes.txt
    

    Git records snapshots, so it detects the rename from the resulting content when useful.

  11. Карта 11

    Въпрос

    List local branches and show which one is current.

    Отговор

    git branch lists local branches and marks the current one with *.

    git branch
    

    It doesn't switch branches.

  12. Карта 12

    Въпрос

    Switch the working tree to the existing branch feature/login.

    Отговор

    git switch feature/login switches to that branch.

    git switch feature/login
    

    Git updates the index and working tree, and refuses if the switch would overwrite local work. Older instructions often use git checkout for branch switching; switch states the intent more clearly.

  13. Карта 13

    Въпрос

    Show every configured remote with its fetch and push URL.

    Отговор

    git remote -v lists remote names and URLs.

    git remote -v
    

    A remote name such as origin is a local shortcut, not a special server type.

  14. Карта 14

    Въпрос

    Read a compact one-line commit history.

    Отговор

    git log --oneline prints one abbreviated entry per commit.

    git log --oneline
    

    The newest reachable commit appears first.

  15. Карта 15

    Въпрос

    Discard unstaged edits to tracked notes.txt.

    Отговор

    git restore notes.txt replaces the working-tree file with the indexed version.

    git restore notes.txt
    

    This is destructive for those unstaged edits. Check git diff -- notes.txt first when unsure.

  16. Карта 16

    Въпрос

    Clone ../origin.git while naming the local directory sandbox.

    Отговор

    git clone ../origin.git sandbox separates the source location from the local directory name.

    git clone ../origin.git sandbox
    

    Run it from the parent directory where sandbox should be created.

  17. Карта 17

    Въпрос

    Read the effective commit email in the current repository.

    Отговор

    git config --get user.email prints the selected configuration value.

    git config --get user.email
    

    Repository-local configuration overrides a global value.

  18. Карта 18

    Въпрос

    Get a compact status that still shows branch information.

    Отговор

    git status --short --branch prints the branch line plus two-column path states.

    git status --short --branch
    

    The left column describes the index; the right column describes the working tree.

  19. Карта 19

    Въпрос

    Review what is staged for the next commit.

    Отговор

    git diff --staged compares the index with HEAD.

    git diff --staged
    

    --cached is the common equivalent spelling.

  20. Карта 20

    Въпрос

    Interactively stage selected hunks from notes.txt.

    Отговор

    git add -p notes.txt lets you accept or reject each patch hunk.

    git add -p notes.txt
    

    This is useful when one file contains changes for more than one commit.

  21. Карта 21

    Въпрос

    Open the configured editor to write a commit message for the staged snapshot.

    Отговор

    git commit opens the commit-message editor.

    git commit
    

    Git still commits only the staged content.

  22. Карта 22

    Въпрос

    Stop tracking local.env but keep the file in the working tree.

    Отговор

    git rm --cached local.env stages removal from the index without deleting the local file.

    git rm --cached local.env
    

    Add the path to an ignore rule if it shouldn't be staged again.

  23. Карта 23

    Въпрос

    Create feature/login at the current commit without switching to it.

    Отговор

    git branch feature/login creates the branch reference.

    git branch feature/login
    

    Use git switch -c feature/login when you want to create and switch in one step.

  24. Карта 24

    Въпрос

    Add ../upstream.git as a remote named upstream.

    Отговор

    git remote add upstream ../upstream.git stores that remote configuration.

    git remote add upstream ../upstream.git
    

    It doesn't fetch any refs until you run git fetch upstream.

  25. Карта 25

    Въпрос

    View a compact decorated commit graph across all local refs.

    Отговор

    git log --oneline --graph --decorate --all combines history, topology, and ref names.

    git log --oneline --graph --decorate --all
    

    It is a read-only way to understand how branches relate.

  26. Карта 26

    Въпрос

    Inspect the current commit's metadata and patch.

    Отговор

    git show HEAD displays the commit and its changes.

    git show HEAD
    

    Replace HEAD with another revision when needed.

  27. Карта 27

    Въпрос

    Create feature/search at the current commit and switch to it.

    Отговор

    git switch -c feature/search creates and checks out the branch.

    git switch -c feature/search
    

    New commits now advance feature/search.

  28. Карта 28

    Въпрос

    List the paths currently known to the index.

    Отговор

    git ls-files prints tracked and staged paths.

    git ls-files
    

    It is more precise than a filesystem listing when you need Git's view.

  29. Карта 29

    Въпрос

    Refresh remote-tracking refs from origin without integrating them.

    Отговор

    git fetch origin downloads objects and updates origin/* refs.

    git fetch origin
    

    Your current branch and working tree stay in place.

  30. Карта 30

    Въпрос

    Unstage notes.txt while keeping its working-tree edits.

    Отговор

    git restore --staged notes.txt restores the index entry from HEAD by default.

    git restore --staged notes.txt
    

    The file's edited content remains in the working tree.

  31. Карта 31

    Въпрос

    Temporarily store tracked work with the label WIP login.

    Отговор

    git stash push -m "WIP login" saves tracked staged and unstaged changes, then cleans them from the worktree.

    git stash push -m "WIP login"
    

    Untracked files stay put unless you add -u.

  32. Карта 32

    Въпрос

    Check how the current branch differs from its configured upstream.

    Отговор

    git status --branch reports ahead, behind, or diverged state when an upstream exists.

    git status --branch
    

    It doesn't contact the remote, so fetch first when freshness matters.

  33. Карта 33

    Въпрос

    Compare the snapshots at main and feature/login.

    Отговор

    git diff main feature/login shows changes needed to turn the first tree into the second.

    git diff main feature/login
    

    This compares the two named tips, not their merge base.

  34. Карта 34

    Въпрос

    Stage all additions, modifications, and deletions in the current repository.

    Отговор

    git add -A updates the index for every path in scope.

    git add -A
    

    Review git diff --staged before committing a broad change.

  35. Карта 35

    Въпрос

    Replace the current local commit with a corrected snapshot but keep its message.

    Отговор

    git commit --amend --no-edit creates a replacement commit from the current index.

    git commit --amend --no-edit
    

    Amending rewrites the commit ID. Avoid it after sharing the commit unless the team expects a history update.

  36. Карта 36

    Въпрос

    Rename the current branch to feature/auth.

    Отговор

    git branch -m feature/auth renames the checked-out branch.

    git branch -m feature/auth
    

    If the old name was already pushed, coordinate the remote rename separately.

  37. Карта 37

    Въпрос

    Return to the branch you were on immediately before this one.

    Отговор

    git switch - switches to the previously checked-out branch.

    git switch -
    

    It is handy for moving between two branches.

  38. Карта 38

    Въпрос

    Integrate feature/login into the current branch.

    Отговор

    git merge feature/login joins the named branch into the current branch.

    git merge feature/login
    

    The result may be a fast-forward, merge commit, or conflict, depending on history and options.

  39. Карта 39

    Въпрос

    Fetch only the main branch from origin.

    Отговор

    git fetch origin main downloads that branch and records the fetched tip in FETCH_HEAD.

    git fetch origin main
    

    It doesn't merge or move your current branch.

  40. Карта 40

    Въпрос

    Update the current branch only when the remote change can fast-forward it.

    Отговор

    git pull --ff-only fetches, then refuses to create a merge commit or rebase.

    git pull --ff-only
    

    A refusal leaves the divergent histories for you to inspect.

  41. Карта 41

    Въпрос

    Push the current branch feature/login to origin.

    Отговор

    git push origin feature/login updates the same-named remote branch.

    git push origin feature/login
    

    It doesn't configure an upstream unless your settings do that automatically.

  42. Карта 42

    Въпрос

    Read commits that changed notes.txt.

    Отговор

    git log -- notes.txt limits history to commits affecting that path.

    git log -- notes.txt
    

    The -- separates revisions and options from the path.

  43. Карта 43

    Въпрос

    Print notes.txt exactly as it exists in HEAD without switching commits.

    Отговор

    git show HEAD:notes.txt reads the blob at that revision and path.

    git show HEAD:notes.txt
    

    This doesn't modify the working-tree file.

  44. Карта 44

    Въпрос

    Search tracked working-tree files for the text TODO, including unstaged edits.

    Отговор

    git grep TODO searches tracked files in the working tree, including their unstaged content.

    git grep TODO
    

    It skips untracked files by default.

  45. Карта 45

    Въпрос

    Show the commit and author associated with each line of notes.txt.

    Отговор

    git blame notes.txt annotates each line with its last recorded change.

    git blame notes.txt
    

    Use it as a history lead, not as proof that one person owns the current behavior.

  46. Карта 46

    Въпрос

    Move the current branch back one commit while keeping the changes unstaged.

    Отговор

    git reset HEAD~1 performs the default mixed reset.

    git reset HEAD~1
    

    It rewrites the local branch tip but leaves the changed files in the working tree.

  47. Карта 47

    Въпрос

    Stash tracked and untracked work together with the label WIP search.

    Отговор

    git stash push -u -m "WIP search" includes untracked files.

    git stash push -u -m "WIP search"
    

    Ignored files still stay out unless you deliberately use the stronger --all option.

  48. Карта 48

    Въпрос

    List local tags whose names start with v1..

    Отговор

    git tag --list "v1.*" filters the local tag names.

    git tag --list "v1.*"
    

    Listing tags doesn't contact a remote.

  49. Карта 49

    Въпрос

    Resolve HEAD to its full object ID.

    Отговор

    git rev-parse HEAD prints the object name selected by the revision.

    git rev-parse HEAD
    

    This is useful in scripts that need an exact commit ID.

  50. Карта 50

    Въпрос

    Review prose edits as changed words instead of whole lines.

    Отговор

    git diff --word-diff highlights inline word-level changes.

    git diff --word-diff
    

    It changes the display only; repository state stays untouched.

  51. Карта 51

    Въпрос

    Integrate feature/login only if the current branch can fast-forward.

    Отговор

    git merge --ff-only feature/login refuses histories that require a merge commit.

    git merge --ff-only feature/login
    

    The refusal is a safety check, not a partial merge.

  52. Карта 52

    Въпрос

    Fetch origin and remove remote-tracking refs that the remote no longer has.

    Отговор

    git fetch --prune origin refreshes refs and prunes stale origin/* names.

    git fetch --prune origin
    

    It doesn't delete local branches.

  53. Карта 53

    Въпрос

    List commits reachable from feature/login but not from main.

    Отговор

    git log main..feature/login --oneline shows that one-sided revision range.

    git log main..feature/login --oneline
    

    The order around .. matters.

  54. Карта 54

    Въпрос

    Replace working-tree notes.txt with its version from HEAD~1.

    Отговор

    git restore --source=HEAD~1 notes.txt copies the older blob into the working tree.

    git restore --source=HEAD~1 notes.txt
    

    This overwrites current unstaged edits to notes.txt. Diff, copy, or otherwise protect wanted edits first; then review and stage the restored version if you want to keep it.

  55. Карта 55

    Въпрос

    Create branch hotfix in an additional working tree at ../hotfix.

    Отговор

    git worktree add ../hotfix -b hotfix creates the branch and checks it out there.

    git worktree add ../hotfix -b hotfix
    

    The original working tree stays on its current branch.

  56. Карта 56

    Въпрос

    Push feature/login and configure origin/feature/login as its upstream.

    Отговор

    git push -u origin feature/login pushes the branch and records upstream tracking.

    git push -u origin feature/login
    

    Later git status, git pull, and git push can use that relationship.

  57. Карта 57

    Въпрос

    Follow likely moved or copied lines while blaming notes.txt.

    Отговор

    git blame -M -C notes.txt adds move and copy detection heuristics.

    git blame -M -C notes.txt
    

    The result is still a clue for investigation, not an ownership verdict.

  58. Карта 58

    Въпрос

    Replay the current branch's local commits on top of main.

    Отговор

    git rebase main rewrites those commits onto the new base.

    git rebase main
    

    Use it on unshared work, or coordinate before rewriting commits other people may use.

  59. Карта 59

    Въпрос

    Move the branch back one commit while keeping all reverted changes staged.

    Отговор

    git reset --soft HEAD~1 moves HEAD but leaves the index and working tree intact.

    git reset --soft HEAD~1
    

    This rewrites the local branch tip and is best kept to unshared history.

  60. Карта 60

    Въпрос

    Create an annotated release tag v1.0.0 at the current commit.

    Отговор

    git tag -a v1.0.0 -m "Release 1.0.0" creates a tag object with a message.

    git tag -a v1.0.0 -m "Release 1.0.0"
    

    Tags aren't pushed automatically unless you push them explicitly.

  61. Карта 61

    Въпрос

    Start a regression search with HEAD known bad and HEAD~4 known good.

    Отговор

    git bisect start, followed by bad and good boundaries, begins binary search through the range.

    git bisect start
    git bisect bad HEAD
    git bisect good HEAD~4
    

    Git checks out a midpoint for you to test.

  62. Карта 62

    Въпрос

    Fetch the upstream branch, then replay local commits on top of it.

    Отговор

    git pull --rebase combines fetch with a rebase-based integration.

    git pull --rebase
    

    It rewrites local commits, so inspect the branch and keep shared-history expectations in mind.

  63. Карта 63

    Въпрос

    Commit the staged update as Update notes while leaving unstaged edits out.

    Отговор

    git commit -m "Update notes" records the index, not every working-tree edit.

    git commit -m "Update notes"
    

    Review both git diff --staged and git diff when the split matters.

  64. Карта 64

    Въпрос

    Undo the current non-merge commit with a new commit instead of moving the branch backward.

    Отговор

    git revert HEAD applies the inverse of the current non-merge commit and records it as a new commit.

    git revert HEAD
    

    For a merge commit, inspect its parents and use the mainline form taught later: git revert -m <parent-number> <merge-commit>. Revert preserves shared history, which usually makes it safer than reset for published commits.

  65. Карта 65

    Въпрос

    Delete the fully merged local branch feature/login.

    Отговор

    git branch -d feature/login deletes the branch only when Git considers it merged.

    git branch -d feature/login
    

    The lowercase -d guard helps prevent accidental loss of unmerged branch tips.

  66. Карта 66

    Въпрос

    Inspect HEAD~1 without moving any branch name.

    Отговор

    git switch --detach HEAD~1 checks out the commit in detached-HEAD mode.

    git switch --detach HEAD~1
    

    Create a branch before leaving if you make commits you want to keep.

  67. Карта 67

    Въпрос

    Find one best common ancestor of main and feature/login.

    Отговор

    git merge-base main feature/login prints one best merge base.

    git merge-base main feature/login
    

    Criss-cross histories can have multiple equally best bases. Use git merge-base --all main feature/login when every best base matters; without --all, Git chooses one unspecified best base.

  68. Карта 68

    Въпрос

    Print the top-level directory of the current working tree.

    Отговор

    git rev-parse --show-toplevel resolves the repository root path.

    git rev-parse --show-toplevel
    

    It fails outside a working tree, which is useful in scripts that require one.

  69. Карта 69

    Въпрос

    Inspect recent local movements of HEAD.

    Отговор

    git reflog --oneline shows the local reference-update history in compact form.

    git reflog --oneline
    

    It can reveal commits hidden by reset or rebase while their objects still exist.

  70. Карта 70

    Въпрос

    List stashes, then summarize the newest stash's changed paths.

    Отговор

    git stash list names the entries, and git stash show --stat stash@{0} summarizes the newest one.

    git stash list
    git stash show --stat stash@{0}
    

    Neither command removes or applies the stash.

  71. Карта 71

    Въпрос

    Apply the tip commit from feature/login without conflicts and record where it came from.

    Отговор

    git cherry-pick -x feature/login applies the commit and, when it applies without conflicts, adds a source-commit line to the message.

    git cherry-pick -x feature/login
    

    Use -x when the trace is useful and the picked commit is public enough to name.

  72. Карта 72

    Въпрос

    Preview which untracked files under scratch/ Git would delete.

    Отговор

    git clean -nd -- scratch/ performs a scoped dry run.

    git clean -nd -- scratch/
    

    Run the preview before replacing -n with -f; ignored files aren't included here.

  73. Карта 73

    Въпрос

    Identify conflicted paths after a merge stops.

    Отговор

    git status --short marks unmerged paths with combinations such as UU.

    git status --short
    

    Resolve each path, stage the result, then complete the merge commit—or abort the merge.

  74. Карта 74

    Въпрос

    Continue a rebase after resolving and staging its conflicts.

    Отговор

    git rebase --continue records the resolved step and moves to the next commit.

    git rebase --continue
    

    If the resolution is wrong or the rewrite is no longer wanted, abort instead.

  75. Карта 75

    Въпрос

    List every working tree attached to the repository.

    Отговор

    git worktree list shows each path, checked-out commit, and branch when attached.

    git worktree list
    

    A branch normally can't be checked out in two worktrees at once.

  76. Карта 76

    Въпрос

    Fetch and integrate the upstream with merge semantics rather than rebase.

    Отговор

    git pull --no-rebase fetches, then merges the selected upstream.

    git pull --no-rebase
    

    Use an explicit policy so the integration behavior isn't a surprise.

  77. Карта 77

    Въпрос

    Interactively discard selected unstaged hunks from notes.txt.

    Отговор

    git restore -p notes.txt asks which working-tree hunks to restore from the index.

    git restore -p notes.txt
    

    Accepted hunks are discarded, so review each prompt carefully.

  78. Карта 78

    Въпрос

    Delete the remote branch feature/login from origin.

    Отговор

    git push origin --delete feature/login removes that remote ref.

    git push origin --delete feature/login
    

    It doesn't delete anyone's local branch or existing commits immediately.

  79. Карта 79

    Въпрос

    Mark HEAD~4 as a known good boundary during a bisect session.

    Отговор

    git bisect good HEAD~4 tells Git that the named commit doesn't contain the bug.

    git bisect good HEAD~4
    

    Git uses good and bad boundaries to choose the next midpoint.

  80. Карта 80

    Въпрос

    Delete the local tag v1.0.0.

    Отговор

    git tag -d v1.0.0 removes the local tag reference.

    git tag -d v1.0.0
    

    A remote copy, if any, needs a separate remote update.

  81. Карта 81

    Въпрос

    Move the branch back one commit and discard the index and working-tree changes.

    Отговор

    git reset --hard HEAD~1 makes the branch, index, and tracked working tree match HEAD~1.

    git reset --hard HEAD~1
    

    This is destructive. It can also delete or overwrite untracked files or directories that obstruct paths tracked by the target commit. Confirm the target and move wanted work first.

  82. Карта 82

    Въпрос

    Give the current commit a human-readable name based on reachable tags.

    Отговор

    git describe --tags --always uses the nearest tag when possible and falls back to an object name.

    git describe --tags --always
    

    It reads history without creating or moving a tag.

  83. Карта 83

    Въпрос

    Continue a cherry-pick after resolving and staging its conflicts.

    Отговор

    git cherry-pick --continue finishes the current picked commit.

    git cherry-pick --continue
    

    Git may continue to another commit if the original request included a sequence.

  84. Карта 84

    Въпрос

    Delete ordinary, non-ignored untracked files and directories only under scratch/.

    Отговор

    git clean -fd -- scratch/ removes ordinary, non-ignored untracked files and directories under that path.

    git clean -fd -- scratch/
    

    It leaves ignored content and nested Git repositories in place. This can't be recovered through normal Git history, so run the matching dry run first.

  85. Карта 85

    Въпрос

    Apply the inverse of the current non-merge commit to the index and working tree without committing yet.

    Отговор

    git revert --no-commit HEAD prepares the inverse of the current non-merge commit for inspection.

    git revert --no-commit HEAD
    

    For a merge commit, inspect its parents and use the mainline form taught later: git revert -m <parent-number> <merge-commit>. You can combine or edit the prepared change before creating a commit.

  86. Карта 86

    Въпрос

    Apply the newest stash while keeping it in the stash list.

    Отговор

    git stash apply stash@{0} reapplies the entry without dropping it.

    git stash apply stash@{0}
    

    Use pop only when you want a successful apply to remove the entry automatically.

  87. Карта 87

    Въпрос

    Create branch recovered at the previous recorded location of HEAD.

    Отговор

    git branch recovered HEAD@{1} gives the reflog entry a durable branch name.

    git branch recovered HEAD@{1}
    

    Inspect the entry first; reflog positions change as new reference updates happen.

  88. Карта 88

    Въпрос

    Abandon the current conflicted merge and return to its pre-merge state.

    Отговор

    git merge --abort stops the in-progress merge.

    git merge --abort
    

    Uncommitted changes that predated the merge can make exact reconstruction harder, so start risky merges from a clear state.

  89. Карта 89

    Въпрос

    Unstage notes.txt with the older path-specific reset form.

    Отговор

    git reset HEAD -- notes.txt resets only the index entry and keeps working-tree edits.

    git reset HEAD -- notes.txt
    

    Modern instructions usually prefer git restore --staged notes.txt for this job.

  90. Карта 90

    Въпрос

    Remove the clean linked working tree at ../hotfix.

    Отговор

    git worktree remove ../hotfix removes that working tree and its administrative record.

    git worktree remove ../hotfix
    

    It refuses a dirty working tree unless you force it; inspect and save work instead of forcing by habit.

  91. Карта 91

    Въпрос

    Force-update feature/login only if its remote tip matches your local origin/feature/login expectation.

    Отговор

    git push --force-with-lease origin feature/login compares the remote branch with the local remote-tracking ref before force-updating.

    git push --force-with-lease origin feature/login
    

    Background or automatic fetches can move that local ref and weaken the check. Inspect the fetched tip, coordinate the rewrite, and use an explicit <ref>:<expect> lease when exact protection matters.

  92. Карта 92

    Въпрос

    Abandon the current rebase and restore the branch to its pre-rebase state.

    Отговор

    git rebase --abort stops the rewrite and restores the original branch tip.

    git rebase --abort
    

    Use it when the conflict resolution or rewrite plan isn't worth continuing.

  93. Карта 93

    Въпрос

    Revert the current merge commit while keeping its first parent as the mainline.

    Отговор

    git revert -m 1 HEAD creates an inverse change relative to parent 1.

    git revert -m 1 HEAD
    

    Choosing the wrong mainline changes the meaning, so inspect the merge's parents first. Its ancestors remain integrated in history, which means a later merge may not restore the reverted tree changes automatically.

  94. Карта 94

    Въпрос

    End a bisect session and return to the branch or commit checked out before it.

    Отговор

    git bisect reset restores the pre-bisect checkout.

    git bisect reset
    

    Run it after identifying the first bad commit or when abandoning the search.

  95. Карта 95

    Въпрос

    Read the reflog specifically for HEAD.

    Отговор

    git reflog show HEAD displays local movements recorded for HEAD.

    git reflog show HEAD
    

    Reflogs are local recovery records; they aren't a shared remote audit log.

  96. Карта 96

    Въпрос

    Abandon the current conflicted cherry-pick.

    Отговор

    git cherry-pick --abort restores the state from before the cherry-pick sequence.

    git cherry-pick --abort
    

    Use it instead of stacking unrelated cleanup commands onto a failed pick.

  97. Карта 97

    Въпрос

    Interactively edit the last three local commits before sharing them.

    Отговор

    git rebase -i HEAD~3 opens a plan for reordering, editing, squashing, or dropping those commits.

    git rebase -i HEAD~3
    

    Every changed commit gets a new ID. Keep interactive rebase to unshared work unless everyone has coordinated.

  98. Карта 98

    Въпрос

    Run ./test.sh automatically at each midpoint of an active bisect.

    Отговор

    git bisect run ./test.sh classifies commits from the script's exit status.

    git bisect run ./test.sh
    

    The test must be deterministic: exit 0 for good, 1–127 except 125 for bad, and 125 to skip an untestable commit.

Abstract branching commit graph on a dark terminal-inspired background.

98 карти

Git Commands Flashcards: Everyday Workflow, Branching & Recovery

Учете с това тесте безплатно

Nibomo се отваря, за да започнете да учите.