• ᴥ •つ TOP

You can unarchive a GitHub repository from the command line using the following format:

gh repo unarchive username/repo-name

For example, to unarchive a repository named foo from your account (let's say madelen), run the following command:

$ gh repo unarchive madelen/foo

Let's say you have many archived repositories, and you need to unarchive each one to make changes to the author and email in the commit history. You can either manually navigate to each repository on GitHub, go to Settings, and unarchive them one by one, or, you can use gh repo list with the JSON option to filter out all repository names and chain it with another command to unarchive them.

The gh CLI provides a --json=<field> option. We can use the nameWithOwner field to get repositories in the username/repo-name format.

$ gh repo list --json=nameWithOwner --limit 1000 -q ".[].nameWithOwner"

Output:

madelen/foo madelen/bar madelen/baz madelen/qux

Now, chain this result from the first command with a second command using the pipe symbol to unarchive them.

$ gh repo list --json=nameWithOwner --limit 1000 -q ".[].nameWithOwner" | xargs -n1 gh repo unarchive -y

For a repository that is already unarchived, the command will display a message indicating that the repository is already unarchived. It's not an error, so as a result, all repositories will be unarchived after the command is processed.

← prev postnext post →