Clean Up Your GitHub Profile by Bulk Archiving Repos
If you have been on github for more than a few months, you most likely have been accumulating repositories.
While it’s great to see your progress, you might not want older, unfinished projects cluttering your profile.
Instead of deleting them and losing your stats, you can archive them.
If you are not embarassed of your former self, you are not growing fast enough.
Prerequisites
What you will need:
gh
: github’s cli tooljq
: a very powerful tool for working with json datafzf
: a fast, versatile fuzzy finderxargs
: a utility for executing commands on the output of other commands
These tools are must-haves in your developer’s toolbox for creating efficient workflows.
Spending some time on their documentations will be save you countless hours down the track.
TL;DR:
gh repo list --visibility public --no-archived --json name |\
jq -r ".[].name" |\
fzf -m --print0 |\
xargs -0 -i {} gh repo archive -y {}
Step By Step Explanation
- Login in github’s cli:
Simply run gh
and follow the prompts.
- Get a List of Repositories:
Fetch a list of your public repositories that are not archived. use json to output only the names.
gh repo list --visiblity public --no-archived --json name
- Use
jq
to Extract the Names in a List:
Extract the value of the name for each entry and strip the quotes (-r
).
jq -r ".[].name"
- Select Repositories with
fzf
:
Pipe the list of names to fzf
in multi-select mode (-m
), separating the result by the ’null’ value (--print0
).
fzf -m --print0
- Archive Selected Repositories:
Finally, pass the selected names to gh repo archive -y
via xargs
.
We skip the confirmation with -y
.
We inform xargs
that the list is separated by the ’null’ character (-0
) and use -i
to execute the command for each argument in the list.
Complete Command
Putting it all together, the command looks like this:
gh repo list --visibility public --no-archived --json name |\
jq -r ".[].name" |\
fzf -m --print0 |\
xargs -0 -i {} gh repo archive -y {}
Execution
Run the command, use tab
to select repositories and press enter
to confirm.
You should see an output similar to this:
✓ archived repository abitbetterthanyesterday/angular-todo
✓ archived repository abitbetterthanyesterday/zxb
✓ archived repository abitbetterthanyesterday/c-lisp
✓ archived repository abitbetterthanyesterday/web-dev-course
✓ archived repository abitbetterthanyesterday/zefo
...
Enjoy,
Aloys