Archive Git repositories with Shell Script

Shell script to clone repositories at a specific branch, remove the .git folder, and have a clean, archived copy of the repository.

Kanan Rahimov
7 min readDec 25, 2022

Git Repositories and Branch Names

Recently, I needed to archive multiple Git repositories into a single Git repository. In addition, some of these archived repositories have multiple branches worth archiving. So, I needed to support a format like this:

"git@github.com:KenanBek/dbui.git;main,dev"
"git@github.com:KenanBek/django-skeleton.git;master"

Each line contains,

  • Git URL;
  • Comma (,) separate list of branch names;

Git URL and branch names are separated by a semicolon (;).

Shell Script to Archive

The goal is to have a simple shell script that will automate the following steps:

  1. Parse a list in the above-provided format and get repository URL and branch names;
  2. Iterate over each repository and branch, check commit-hash;
  3. If there are changes, clone the repository at each branch (e.g., repo1-main, repo1-dev, repo2-main, etc.);

--

--