Archive the Correct GitHub Repository with gh
You will finish with a checked command for archiving one GitHub repository from a Linux shell, while keeping the confirmation step and a recovery path visible. The examples match GitHub CLI 2.87.3, installed here on 23 September 2026. Allow about ten minutes, plus time to check the repository name with the people who maintain it.
The route
Jump straight to the step you need, or tick off Done means at the end.
You need the gh package, an authenticated GitHub CLI session with permission to administer the repository, and the repository's owner and name. Archiving changes the repository's state on GitHub. It is not a local Git operation, so a clean working tree does not make an unsafe target safe.
1. Check the installed command
Start with read-only checks. They do not need elevated privileges and do not contact a repository-changing endpoint:
$ gh --version
gh version 2.87.3 (2026-02-23)
$ gh repo archive --help
Archive a GitHub repository.
With no argument, archives the current repository.
The command's complete form is gh repo archive [repository] [flags]. The only option documented by this installed version is -y or --yes, which skips the confirmation prompt. There is no flag here for selecting a branch, deleting a clone or making an archive temporary.
Checkpoint
If the version or help output is different, stop and read that version's help before copying the examples below.
2. Confirm the repository identity
Prefer an explicit repository argument when you are archiving anything other than the repository you are deliberately working in. Use the OWNER/REPOSITORY form:
$ gh repo view EXAMPLE_OWNER/EXAMPLE_REPOSITORY --json nameWithOwner,isArchived
{
"nameWithOwner": "EXAMPLE_OWNER/EXAMPLE_REPOSITORY",
"isArchived": false
}
Replace both placeholder values with the real owner and repository name. Treat a result of true as a stop condition: it is already archived, so do not repeat the state-changing command merely to obtain a different message. If the repository is under an organisation, check that you have identified the organisation rather than your personal fork.
When the current directory is itself a clone of the intended repository, the argument may be omitted. That default is convenient but easy to misread when several terminals or clones are open. Establish the current target first:
$ gh repo view --json nameWithOwner,isArchived
{
"nameWithOwner": "EXAMPLE_OWNER/EXAMPLE_REPOSITORY",
"isArchived": false
}
The JSON query is a separate inspection step. It does not archive anything. If it shows a different owner or name from the change record, close the shell or move to the correct directory before continuing.
3. Archive with the confirmation prompt
Archiving is an administrative action. Read the target printed by the prompt, then answer only when it matches the repository you just checked:
$ gh repo archive EXAMPLE_OWNER/EXAMPLE_REPOSITORY
? Are you sure you want to archive EXAMPLE_OWNER/EXAMPLE_REPOSITORY? Yes
The exact prompt and success text can vary with the installed CLI and terminal. A prompt is not proof that you selected the right repository, so keep the explicit argument. Do not use --yes for a one-off command until the target and approval have been independently checked.
This change does not require sudo. Elevated Linux privileges do not grant GitHub repository permission and can make it harder to see which user's gh authentication is being used.
4. Verify the archived state
After the command returns successfully, query the same fully qualified repository:
$ gh repo view EXAMPLE_OWNER/EXAMPLE_REPOSITORY --json nameWithOwner,isArchived
{
"nameWithOwner": "EXAMPLE_OWNER/EXAMPLE_REPOSITORY",
"isArchived": true
}
If the command reports an error, do not infer the state from a partial message. Run the read-only query again and record the result. A permission failure, a wrong repository name and an already archived repository need different follow-up. Also tell any automation or contributors that the repository is now archived, because local clones may continue to exist even though the remote state has changed.
5. Recover from an incorrect archive
There is no undo option on gh repo archive. If the wrong repository was archived, stop other repository administration and confirm the recovery decision with the owner or organisation administrator. GitHub CLI provides a separate gh repo unarchive command in current releases:
$ gh repo unarchive EXAMPLE_OWNER/EXAMPLE_REPOSITORY
$ gh repo view EXAMPLE_OWNER/EXAMPLE_REPOSITORY --json nameWithOwner,isArchived
{
"nameWithOwner": "EXAMPLE_OWNER/EXAMPLE_REPOSITORY",
"isArchived": false
}
Check gh repo unarchive --help before using that recovery command if your installed CLI is older or newer than the version documented here. If unarchiving is unavailable or denied, use the repository settings in GitHub with an administrator rather than guessing at an API request.
Done means
- The installed
ghversion and the archive help were checked. - The owner and repository name were confirmed before the change.
- The normal command was run with its confirmation prompt visible.
- The same repository reports
isArchived: trueafterwards. - No
sudo, branch option or destructive local Git command was used. - A wrong target can be restored with the separately verified unarchive workflow.